mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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:
co-authored by
Claude Sonnet 4.6
parent
1da0306b61
commit
2fe850c070
@@ -58,60 +58,66 @@ 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) {
|
||||||
title: const Text('Register Device'),
|
void save() {
|
||||||
content: Form(
|
if (formKey.currentState?.validate() ?? false) {
|
||||||
key: formKey,
|
formKey.currentState?.save();
|
||||||
child: Column(
|
Navigator.of(context).pop(true);
|
||||||
mainAxisSize: MainAxisSize.min,
|
}
|
||||||
children: [
|
}
|
||||||
TextFormField(
|
|
||||||
decoration: const InputDecoration(labelText: 'Owner'),
|
return AlertDialog(
|
||||||
validator: (value) => value == null || value.trim().isEmpty
|
title: const Text('Register Device'),
|
||||||
? 'Owner is required'
|
content: Form(
|
||||||
: null,
|
key: formKey,
|
||||||
onSaved: (value) => owner = value?.trim() ?? '',
|
child: Column(
|
||||||
),
|
mainAxisSize: MainAxisSize.min,
|
||||||
const SizedBox(height: 16),
|
children: [
|
||||||
DropdownButtonFormField<DeviceType>(
|
TextFormField(
|
||||||
initialValue: deviceType,
|
decoration: const InputDecoration(labelText: 'Owner'),
|
||||||
decoration: const InputDecoration(labelText: 'Device Type'),
|
autofocus: true,
|
||||||
items: DeviceType.values
|
onFieldSubmitted: (_) => save(),
|
||||||
.map(
|
validator: (value) => value == null || value.trim().isEmpty
|
||||||
(t) => DropdownMenuItem(
|
? 'Owner is required'
|
||||||
value: t,
|
: null,
|
||||||
child: Row(
|
onSaved: (value) => owner = value?.trim() ?? '',
|
||||||
children: [
|
),
|
||||||
Icon(t.icon, size: 16),
|
const SizedBox(height: 16),
|
||||||
const SizedBox(width: 4),
|
DropdownButtonFormField<DeviceType>(
|
||||||
Text(t.label),
|
initialValue: deviceType,
|
||||||
],
|
decoration: const InputDecoration(labelText: 'Device Type'),
|
||||||
|
items: DeviceType.values
|
||||||
|
.map(
|
||||||
|
(t) => DropdownMenuItem(
|
||||||
|
value: t,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(t.icon, size: 16),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(t.label),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
.toList(),
|
||||||
.toList(),
|
onChanged: (value) =>
|
||||||
onChanged: (value) =>
|
setDialogState(() => deviceType = value ?? deviceType),
|
||||||
setDialogState(() => deviceType = value ?? deviceType),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
actions: [
|
||||||
actions: [
|
TextButton(
|
||||||
TextButton(
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
child: const Text('Cancel'),
|
||||||
child: const Text('Cancel'),
|
),
|
||||||
),
|
TextButton(
|
||||||
TextButton(
|
onPressed: save,
|
||||||
onPressed: () {
|
child: const Text('Save'),
|
||||||
if (formKey.currentState?.validate() ?? false) {
|
),
|
||||||
formKey.currentState?.save();
|
],
|
||||||
Navigator.of(context).pop(true);
|
);
|
||||||
}
|
},
|
||||||
},
|
|
||||||
child: const Text('Save'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user