Description
Happens after the keyboard event refactor landed.
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 787 pos 16: 'false': Should never encounter KeyData when transitMode is rawKeyData.
It happens in the following scenario: Register macOS global hot key, on hot key create new flutter window/engine and show it. However I assume this would also happen in different multi window scenarios (and is not necessarily tied to a hot key).
What happens is that cocoa immediately sends NSEventTypeFlagsChanged
to the new window with event.modifierFlags == 256
, which basically means no modifiers.
However the code in FlutterChannelKeyResponder
does this:
case NSEventTypeFlagsChanged:
if (event.modifierFlags < _previouslyPressedFlags) {
type = @"keyup";
} else if (event.modifierFlags > _previouslyPressedFlags) {
type = @"keydown";
} else {
// ignore duplicate modifiers; This can happen in situations like switching
// between application windows when MacOS only sends the up event to new window.
return;
}
_previouslyPressedFlags
is 0, so this always generates key down event even though there aren't any modifiers present. Which in turns sets _transitMode
in HardwareKeyboard
to KeyDataTransitMode.rawKeyData
, because this is sent before any actual ui keyboard event. After this the keyboard no longer works in window resulting in message above.
Potential solution would be either initializing _previouslyPressedFlags
to 256
, or check if event.modifierFlags > 256
before generating key down event.