mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
fix(Desktop): Backspace when editing fields (#552)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
9a7d132d24
commit
a223df1e82
1 changed files with 28 additions and 18 deletions
|
|
@ -14,27 +14,37 @@ class BackIntentDpad extends StatelessWidget {
|
|||
if (AdaptiveLayout.inputDeviceOf(context) == InputDevice.touch) {
|
||||
return child;
|
||||
}
|
||||
return Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
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: <Type, Action<Intent>>{
|
||||
BackIntent: CallbackAction<BackIntent>(
|
||||
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<EditableText>() != null;
|
||||
}
|
||||
}
|
||||
|
||||
class BackIntent extends Intent {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue