Created
January 26, 2022 22:11
-
-
Save elliette/04871fd9513f32d63f91b2b3c00416b7 to your computer and use it in GitHub Desktop.
Keyboard shortcuts and focus demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Keyboard Shorcuts Focus', | |
home: Shortcuts( | |
shortcuts: <LogicalKeySet, Intent>{ | |
LogicalKeySet(LogicalKeyboardKey.escape): const EscapeIntent() | |
}, | |
child: Actions( | |
actions: <Type, Action<Intent>>{ | |
EscapeIntent: EscapeAction(), | |
}, | |
child: Scaffold( | |
body: Center( | |
child: Row( | |
children: const <Widget>[ | |
Spacer(), | |
Expanded( | |
child: TextField(), | |
), | |
Spacer(), | |
], | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class EscapeIntent extends Intent { | |
const EscapeIntent(); | |
} | |
class EscapeAction extends Action<EscapeIntent> { | |
@override | |
Object? invoke(covariant EscapeIntent intent) { | |
print('CALLED ESCAPE.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment