keyMessageHandler property Null safety

KeyMessageHandler? keyMessageHandler
read / write

The global handler for all hardware key messages of Flutter.

Key messages received from the platform are first sent to RawKeyboard's listeners and HardwareKeyboard's handlers, then sent to keyMessageHandler, regardless of the results of HardwareKeyboard's handlers. The result from the handlers and keyMessageHandler are combined and returned to the platform. The handler result is explained below.

This handler is normally set by the FocusManager so that it can control the key event propagation to focused widgets. Applications that use the focus system (see Focus and FocusManager) to receive key events do not need to set this field.

Handler result

Key messages 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"). Some platforms might trigger special alerts if the event is not handled by other controls either (such as the "bonk" noise on macOS).

If you are not using the FocusManager to manage focus, set this attribute to a KeyMessageHandler that returns true if the propagation on the platform should not be continued. 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:

Implementation

KeyMessageHandler? keyMessageHandler;