diff --git a/lib/widgets/shared/back_intent_dpad.dart b/lib/widgets/shared/back_intent_dpad.dart index 2fba1b8..fcb810f 100644 --- a/lib/widgets/shared/back_intent_dpad.dart +++ b/lib/widgets/shared/back_intent_dpad.dart @@ -14,27 +14,37 @@ class BackIntentDpad extends StatelessWidget { if (AdaptiveLayout.inputDeviceOf(context) == InputDevice.touch) { return child; } - return Shortcuts( - shortcuts: { - LogicalKeySet(LogicalKeyboardKey.backspace): const BackIntent(), + return Focus( + canRequestFocus: false, + onKeyEvent: (FocusNode node, KeyEvent event) { + if (event is! KeyDownEvent) { + return KeyEventResult.ignored; + } + + if (event.logicalKey == LogicalKeyboardKey.backspace) { + if (_isEditableTextFocused()) { + return KeyEventResult.ignored; + } else { + context.maybePop(); + return KeyEventResult.handled; + } + } + + return KeyEventResult.ignored; }, - child: Actions( - actions: >{ - BackIntent: CallbackAction( - onInvoke: (intent) async { - final navigator = await context.maybePop(); - if (navigator) { - return true; - } else { - return false; - } - }, - ), - }, - child: child, - ), + child: child, ); } + + bool _isEditableTextFocused() { + final focus = FocusManager.instance.primaryFocus; + if (focus == null) return false; + final ctx = focus.context; + if (ctx == null) return false; + + if (ctx.widget is EditableText) return true; + return ctx.findAncestorWidgetOfExactType() != null; + } } class BackIntent extends Intent {