shortcuts.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. class GridShortcuts extends StatelessWidget {
  4. final Widget child;
  5. const GridShortcuts({required this.child, Key? key}) : super(key: key);
  6. @override
  7. Widget build(BuildContext context) {
  8. return Shortcuts(
  9. shortcuts: bindKeys([]),
  10. child: Actions(
  11. dispatcher: LoggingActionDispatcher(),
  12. actions: const {},
  13. child: child,
  14. ),
  15. );
  16. }
  17. }
  18. Map<ShortcutActivator, Intent> bindKeys(List<LogicalKeyboardKey> keys) {
  19. return {for (var key in keys) LogicalKeySet(key): KeyboardKeyIdent(key)};
  20. }
  21. Map<Type, Action<Intent>> bindActions() {
  22. return {
  23. KeyboardKeyIdent: KeyboardBindingAction(),
  24. };
  25. }
  26. class KeyboardKeyIdent extends Intent {
  27. final KeyboardKey key;
  28. const KeyboardKeyIdent(this.key);
  29. }
  30. class KeyboardBindingAction extends Action<KeyboardKeyIdent> {
  31. KeyboardBindingAction();
  32. @override
  33. void invoke(covariant KeyboardKeyIdent intent) {
  34. // print(intent);
  35. }
  36. }
  37. class LoggingActionDispatcher extends ActionDispatcher {
  38. @override
  39. Object? invokeAction(
  40. covariant Action<Intent> action,
  41. covariant Intent intent, [
  42. BuildContext? context,
  43. ]) {
  44. // print('Action invoked: $action($intent) from $context');
  45. super.invokeAction(action, intent, context);
  46. return null;
  47. }
  48. }