Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Last active July 2, 2023 19:12
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 loic-sharma/7570365e06dee849868f9dad0419ba3f to your computer and use it in GitHub Desktop.
Save loic-sharma/7570365e06dee849868f9dad0419ba3f to your computer and use it in GitHub Desktop.
TextField and Shortcuts
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