keyEventHandler property Null safety

RawKeyEventHandler? keyEventHandler
read / write

A handler for hardware keyboard events that will stop propagation if the handler returns true.

Key events on the platform are given to Flutter to be handled by the engine. If they are not handled, then the platform will continue to distribute the keys (i.e. propagate them) to other (possibly non-Flutter) components in the application. The return value from this handler tells the platform to either stop propagation (by returning true: "event handled"), or pass the event on to other controls (false: "event not handled").

This handler is normally set by the FocusManager so that it can control the key event propagation to focused widgets.

Most applications can use the focus system (see Focus and FocusManager) to receive key events. If you are not using the FocusManager to manage focus, then to be able to stop propagation of the event by indicating that the event was handled, set this attribute to a RawKeyEventHandler. Otherwise, key events will be assumed to not have been handled by Flutter, and will also be sent to other (possibly non-Flutter) controls in the application.

See also:

  • Focus.onKey, a Focus callback attribute that will be given key events distributed by the FocusManager based on the current primary focus.
  • addListener, to add passive key event listeners that do not stop event propagation.


RawKeyEventHandler? keyEventHandler