KeyEventManager class

A singleton class that processes key messages from the platform and dispatches converted messages accordingly.

This class is deprecated, and will be removed. There is no direct substitute planned, since this class will no longer be necessary once RawKeyEvent and associated APIs are removed.

KeyEventManager receives platform key messages by handleKeyData and handleRawKeyMessage, sends converted events to HardwareKeyboard and RawKeyboard for recording keeping, and then dispatches the KeyMessage to keyMessageHandler, the global message handler.

KeyEventManager is typically created, owned, and invoked by ServicesBinding.

On embedder implementation

Currently, Flutter has two sets of key event API pathways running in parallel.

  • The "hardware key event" pathway receives messages from the "flutter/keydata" message channel (embedder API FlutterEngineSendKeyEvent) and dispatches KeyEvent to HardwareKeyboard and some methods such as Focus.onKeyEvent.
  • The deprecated "raw key event" pathway receives messages from the "flutter/keyevent" message channel (SystemChannels.keyEvent) and dispatches RawKeyEvent to RawKeyboard and Focus.onKey as well as similar methods. This pathway will be removed at a future date.

KeyEventManager resolves cross-platform compatibility of keyboard implementations, since legacy platforms might have not implemented the new key data API and only send raw key data on each key message. KeyEventManager recognizes the platform support by detecting whether a message comes from platform channel "flutter/keyevent" before one from "flutter/keydata", or vice versa, at the beginning of the app.

  • If a "flutter/keydata" message is received first, then this platform is considered a modern platform. The hardware key events are stored, and dispatched only when a raw key message is received.
  • If a "flutter/keyevent" message is received first, then this platform is considered a legacy platform. The raw key event is transformed into a hardware key event at best effort. No messages from "flutter/keydata" are expected. This behavior has been deprecated, and will be removed at a future date.

Therefore, to correctly implement a platform that supports FlutterEngineSendKeyEvent, the platform must ensure that FlutterEngineSendKeyEvent is called before sending a message to "flutter/keyevent" at the beginning of the app, and every physical key event is ended with a "flutter/keyevent" message.

  • @Deprecated('No longer supported. Once RawKeyEvent is removed, will no longer be needed. ' 'This feature was deprecated after v3.18.0-2.0.pre.')


KeyEventManager(HardwareKeyboard _hardwareKeyboard, RawKeyboard _rawKeyboard)
Create an instance.


hashCode int
The hash code for this object.
no setterinherited
keyMessageHandler KeyMessageHandler?
The global entrance which handles all key events sent to Flutter.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


clearState() → void
Reset the inferred platform transit mode and related states.
handleKeyData(KeyData data) bool
Dispatch a key data to global and leaf listeners.
handleRawKeyMessage(dynamic message) Future<Map<String, dynamic>>
Handles a raw key message.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.