onKey property Null safety

FocusOnKeyCallback? onKey

A handler for keys that are pressed when this object or one of its children has focus.

This is a legacy API based on RawKeyEvent and will be deprecated in the future. Prefer onKeyEvent instead.

Key events are first given to the FocusNode that has primary focus, and if its onKey method return false, then they are given to each ancestor node up the focus hierarchy in turn. If an event reaches the root of the hierarchy, it is discarded.

This is not the way to get text input in the manner of a text field: it leaves out support for input method editors, and doesn't support soft keyboards in general. For text input, consider TextField, EditableText, or CupertinoTextField instead, which do support these things.


FocusOnKeyCallback? get onKey => _onKey ?? focusNode?.onKey;