diff --git a/lib/screens/settings/settings_screen.dart b/lib/screens/settings/settings_screen.dart index d795108b..c9dbe471 100644 --- a/lib/screens/settings/settings_screen.dart +++ b/lib/screens/settings/settings_screen.dart @@ -970,6 +970,7 @@ class _SettingsScreenState extends State with FocusableTab { required Future Function(int value) onSave, }) { int spinnerValue = currentValue; + final saveFocusNode = FocusNode(); showDialog( context: context, @@ -992,6 +993,8 @@ class _SettingsScreenState extends State with FocusableTab { spinnerValue = value; }); }, + onConfirm: () => saveFocusNode.requestFocus(), + onCancel: () => Navigator.pop(dialogContext), ), const SizedBox(height: 8), Text( @@ -1005,6 +1008,7 @@ class _SettingsScreenState extends State 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 with FocusableTab { }, ); }, - ); + ).then((_) => saveFocusNode.dispose()); } /// Standard numeric input dialog with TextField for non-TV platforms. diff --git a/lib/widgets/tv_number_spinner.dart b/lib/widgets/tv_number_spinner.dart index 6c563e7a..3ab4d90c 100644 --- a/lib/widgets/tv_number_spinner.dart +++ b/lib/widgets/tv_number_spinner.dart @@ -33,6 +33,14 @@ class TvNumberSpinner extends StatefulWidget { /// Called when the value changes. final ValueChanged 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 { 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;