Skip to content

Latest commit

 

History

History
91 lines (64 loc) · 2.56 KB

File metadata and controls

91 lines (64 loc) · 2.56 KB

Hotkeys with CallbackShortcuts

Did you know?

The CallbackShortcuts widget makes it easy to add keyboard shortcuts to your Flutter app.

To use it:

  1. Add one or more key bindings using SingleActivator
  2. Add a Focus widget to capture the desired events
  3. Use callbacks to perform your desired actions


Note: the activators will only be triggered when there's a focused child widget.

The easiest way to do this is to wrap your child widget in a Focus widget with autofocus: true.

If other widgets also rely on active focus, you can explicitly request focus with a FocusNode.


For more details about CallbackShortcuts, check this video:


To dive deeper and learn what to do when things don't work as you expect, watch this three-part series. 👇


If you want to see this technique in action, check my Flutter Tips app (web version):

This supports three different keyboard shortcuts:

  • Left arrow: go to the previous tip
  • Space: favorite/unfavorite a tip
  • Right arrow: go to the next tip

Previous Next
GitHub Self-Hosted Runners Wildcard Variables in Dart 3.7