shouldDispatchEvent method
Whether a key down event, and likewise its accompanying key up event, should be dispatched.
Certain events on some platforms should not be dispatched to listeners
according to Flutter's event model. For example, on macOS, Fn keys are
skipped to be consistent with other platform. On Win32, events dispatched
for IME (VK_PROCESSKEY
) are also skipped.
This method will be called upon every down events. By default, this method always return true. Subclasses should override this method to define the filtering rule for the platform. If this method returns false for an event message, the event will not be dispatched to listeners, but respond with "handled: true" immediately. Moreover, the following up event with the same physical key will also be skipped.
Implementation
@override
bool shouldDispatchEvent() {
// On macOS laptop keyboards, the fn key is used to generate home/end and
// f1-f12, but it ALSO generates a separate down/up event for the fn key
// itself. Other platforms hide the fn key, and just produce the key that
// it is combined with, so to keep it possible to write cross platform
// code that looks at which keys are pressed, the fn key is ignored on
// macOS.
return logicalKey != LogicalKeyboardKey.fn;
}