Auto-focus owner field and submit on Enter in register device dialog

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-29 08:29:50 -04:00
co-authored by Claude Sonnet 4.6
parent 1da0306b61
commit 2fe850c070
+14 -8
View File
@@ -58,7 +58,15 @@ Future<void> showRegisterDeviceDialog(
final saved = await showDialog<bool>( final saved = await showDialog<bool>(
context: context, context: context,
builder: (context) => StatefulBuilder( builder: (context) => StatefulBuilder(
builder: (context, setDialogState) => AlertDialog( builder: (context, setDialogState) {
void save() {
if (formKey.currentState?.validate() ?? false) {
formKey.currentState?.save();
Navigator.of(context).pop(true);
}
}
return AlertDialog(
title: const Text('Register Device'), title: const Text('Register Device'),
content: Form( content: Form(
key: formKey, key: formKey,
@@ -67,6 +75,8 @@ Future<void> showRegisterDeviceDialog(
children: [ children: [
TextFormField( TextFormField(
decoration: const InputDecoration(labelText: 'Owner'), decoration: const InputDecoration(labelText: 'Owner'),
autofocus: true,
onFieldSubmitted: (_) => save(),
validator: (value) => value == null || value.trim().isEmpty validator: (value) => value == null || value.trim().isEmpty
? 'Owner is required' ? 'Owner is required'
: null, : null,
@@ -102,16 +112,12 @@ Future<void> showRegisterDeviceDialog(
child: const Text('Cancel'), child: const Text('Cancel'),
), ),
TextButton( TextButton(
onPressed: () { onPressed: save,
if (formKey.currentState?.validate() ?? false) {
formKey.currentState?.save();
Navigator.of(context).pop(true);
}
},
child: const Text('Save'), child: const Text('Save'),
), ),
], ],
), );
},
), ),
); );