Last active
July 2, 2023 19:12
-
-
Save loic-sharma/7570365e06dee849868f9dad0419ba3f to your computer and use it in GitHub Desktop.
TextField and Shortcuts
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'; | |
class TextFieldSample extends StatelessWidget { | |
const TextFieldSample({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return CallbackShortcuts( | |
bindings: <ShortcutActivator, VoidCallback>{ | |
// This causes the shortcut to handle the 'a' key event | |
// when it bubbles up the focus tree. As a result, the text | |
// field won't receive text input if you press the 'a' key. | |
// Try commenting out this line and typing 'a' in the text field. | |
const CharacterActivator('a'): () { } | |
}, | |
// Try typing the 'a' key in this text field. | |
child: const TextField(), | |
); | |
} | |
} | |
class TextFieldExampleApp extends StatelessWidget { | |
const TextFieldExampleApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: const Text('TextField & Shortcuts')), | |
body: const Center( | |
child: TextFieldSample(), | |
), | |
), | |
); | |
} | |
} | |
void main() => runApp(const TextFieldExampleApp()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment