Skip to content

Instantly share code, notes, and snippets.

@ndugger
Last active September 3, 2022 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndugger/aaeaa9edaabe499aa2ef195af8f810d5 to your computer and use it in GitHub Desktop.
Save ndugger/aaeaa9edaabe499aa2ef195af8f810d5 to your computer and use it in GitHub Desktop.
Flutter Focus Management - Shortcuts & Actions
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
const Map<ShortcutActivator, Intent> appShortcuts = {
SingleActivator(LogicalKeyboardKey.tab): NextFocusIntent(),
SingleActivator(LogicalKeyboardKey.tab, shift: true): PreviousFocusIntent()
};
final Map<Type, Action<Intent>> appActions = {
NextFocusIntent: NextFocusAction(),
PreviousFocusIntent: PreviousFocusAction()
};
class App extends StatelessWidget {
const App({ super.key });
@override
Widget build(BuildContext context) {
return Shortcuts(
shortcuts: appShortcuts,
child: Actions(
actions: appActions,
child: Container()
)
);
}
}
void main() {
runApp(const App());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment