fix: revert key events to raw key events on Linux (#9161)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2024-08-25 00:03:31 +08:00
committed by GitHub
parent d400999b9c
commit aa1e122532
4 changed files with 350 additions and 5 deletions

View File

@@ -27,6 +27,10 @@ class RawKeyFocusScope extends StatelessWidget {
@override
Widget build(BuildContext context) {
// https://github.com/flutter/flutter/issues/154053
final useRawKeyEvents = isLinux && !isWeb;
// FIXME: On Windows, `AltGr` will generate `Alt` and `Control` key events,
// while `Alt` and `Control` are seperated key events for en-US input method.
return FocusScope(
autofocus: true,
child: Focus(
@@ -34,7 +38,14 @@ class RawKeyFocusScope extends StatelessWidget {
canRequestFocus: true,
focusNode: focusNode,
onFocusChange: onFocusChange,
onKeyEvent: (node, event) => inputModel.handleKeyEvent(event),
onKey: useRawKeyEvents
? (FocusNode data, RawKeyEvent event) =>
inputModel.handleRawKeyEvent(event)
: null,
onKeyEvent: useRawKeyEvents
? null
: (FocusNode node, KeyEvent event) =>
inputModel.handleKeyEvent(event),
child: child));
}
}