fix: dpad number input

close #196
This commit is contained in:
edde746
2026-01-24 17:41:12 +01:00
parent e11c7e3eed
commit f5dc67573c
2 changed files with 25 additions and 1 deletions
+5 -1
View File
@@ -970,6 +970,7 @@ class _SettingsScreenState extends State<SettingsScreen> with FocusableTab {
required Future<void> Function(int value) onSave,
}) {
int spinnerValue = currentValue;
final saveFocusNode = FocusNode();
showDialog(
context: context,
@@ -992,6 +993,8 @@ class _SettingsScreenState extends State<SettingsScreen> with FocusableTab {
spinnerValue = value;
});
},
onConfirm: () => saveFocusNode.requestFocus(),
onCancel: () => Navigator.pop(dialogContext),
),
const SizedBox(height: 8),
Text(
@@ -1005,6 +1008,7 @@ class _SettingsScreenState extends State<SettingsScreen> with FocusableTab {
actions: [
TextButton(onPressed: () => Navigator.pop(dialogContext), child: Text(t.common.cancel)),
TextButton(
focusNode: saveFocusNode,
onPressed: () async {
await onSave(spinnerValue);
if (dialogContext.mounted) {
@@ -1018,7 +1022,7 @@ class _SettingsScreenState extends State<SettingsScreen> with FocusableTab {
},
);
},
);
).then((_) => saveFocusNode.dispose());
}
/// Standard numeric input dialog with TextField for non-TV platforms.
+20
View File
@@ -33,6 +33,14 @@ class TvNumberSpinner extends StatefulWidget {
/// Called when the value changes.
final ValueChanged<int> onChanged;
/// Called when the user presses SELECT to confirm.
/// Use this to move focus to a confirm/save button.
final VoidCallback? onConfirm;
/// Called when the user presses BACK to cancel.
/// Use this to close the dialog or cancel the operation.
final VoidCallback? onCancel;
/// Whether the spinner should request focus when built.
final bool autofocus;
@@ -45,6 +53,8 @@ class TvNumberSpinner extends StatefulWidget {
this.step = 1,
this.suffix,
this.autofocus = false,
this.onConfirm,
this.onCancel,
});
@override
@@ -105,6 +115,16 @@ class _TvNumberSpinnerState extends State<TvNumberSpinner> {
final key = event.logicalKey;
if (event is KeyDownEvent) {
// Handle SELECT key to confirm/move to save button
if (key.isSelectKey && widget.onConfirm != null) {
widget.onConfirm!();
return KeyEventResult.handled;
}
// Handle BACK key to cancel
if (key.isBackKey && widget.onCancel != null) {
widget.onCancel!();
return KeyEventResult.handled;
}
if (key.isUpKey || key.isRightKey) {
_startRepeat(_increment);
return KeyEventResult.handled;