Skip to content

Commit ad0ce90

Browse files
committed
refactor: update device selection dialog to use Consumer for KeysViewModel
1 parent 01b96f2 commit ad0ce90

File tree

1 file changed

+57
-55
lines changed

1 file changed

+57
-55
lines changed

lib/views/keys/keys.dart

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -49,67 +49,69 @@ class _KeysPageState extends State<KeysPage> {
4949
await showDialog(
5050
context: context,
5151
barrierDismissible: false,
52-
builder: (_) => AlertDialog(
53-
title: const Text('Select FIDO2 Key'),
54-
content: Column(
55-
mainAxisSize: MainAxisSize.min,
56-
children: [
57-
Row(
58-
children: [
59-
const Expanded(
60-
child: Text('Please choose a key to use (CCID or NFC).'),
61-
),
62-
IconButton(
63-
onPressed: () async {
64-
// Refresh device list
65-
await vm.refreshAvailableDevices();
52+
builder: (_) => Consumer<KeysViewModel>(
53+
builder: (__, vmm, ___) => AlertDialog(
54+
title: const Text('Select FIDO2 Key'),
55+
content: Column(
56+
mainAxisSize: MainAxisSize.min,
57+
children: [
58+
Row(
59+
children: [
60+
const Expanded(
61+
child: Text('Please choose a key to use (CCID or NFC).'),
62+
),
63+
IconButton(
64+
onPressed: () async {
65+
// Refresh device list
66+
await vmm.refreshAvailableDevices();
67+
},
68+
icon: const Icon(Icons.refresh),
69+
tooltip: 'Refresh device list',
70+
),
71+
],
72+
),
73+
const SizedBox(height: 16),
74+
...vmm.availableDevices.map(
75+
(device) => ListTile(
76+
leading: Icon(
77+
device.type == FidoDeviceType.ccid ? Icons.usb : Icons.nfc,
78+
color: Theme.of(context).colorScheme.primary,
79+
),
80+
title: Text(device.name),
81+
subtitle: Text(device.description),
82+
onTap: () {
83+
vmm.submitDeviceSelection(device);
84+
Navigator.of(context).pop();
6685
},
67-
icon: const Icon(Icons.refresh),
68-
tooltip: 'Refresh device list',
69-
),
70-
],
71-
),
72-
const SizedBox(height: 16),
73-
...vm.availableDevices.map(
74-
(device) => ListTile(
75-
leading: Icon(
76-
device.type == FidoDeviceType.ccid ? Icons.usb : Icons.nfc,
77-
color: Theme.of(context).colorScheme.primary,
7886
),
79-
title: Text(device.name),
80-
subtitle: Text(device.description),
81-
onTap: () {
82-
vm.submitDeviceSelection(device);
83-
Navigator.of(context).pop();
84-
},
8587
),
86-
),
87-
if (vm.availableDevices.isEmpty)
88-
const Padding(
89-
padding: EdgeInsets.symmetric(vertical: 8),
90-
child: Text(
91-
'No keys detected. Connect a CCID reader or enable NFC, then refresh.',
92-
style: TextStyle(fontSize: 12),
88+
if (vmm.availableDevices.isEmpty)
89+
const Padding(
90+
padding: EdgeInsets.symmetric(vertical: 8),
91+
child: Text(
92+
'No keys detected. Connect a CCID reader or enable NFC, then refresh.',
93+
style: TextStyle(fontSize: 12),
94+
),
9395
),
94-
),
95-
if (vm.errorMessage != null) const SizedBox(height: 8),
96-
if (vm.errorMessage != null)
97-
Text(
98-
vm.errorMessage!,
99-
style: const TextStyle(color: Colors.red, fontSize: 12),
100-
),
96+
if (vmm.errorMessage != null) const SizedBox(height: 8),
97+
if (vmm.errorMessage != null)
98+
Text(
99+
vmm.errorMessage!,
100+
style: const TextStyle(color: Colors.red, fontSize: 12),
101+
),
102+
],
103+
),
104+
actions: [
105+
TextButton(
106+
onPressed: () {
107+
vmm.cancelDeviceSelection();
108+
Navigator.of(context).pop();
109+
_deviceSelectionDialogOpen = false;
110+
},
111+
child: const Text('Cancel'),
112+
),
101113
],
102114
),
103-
actions: [
104-
TextButton(
105-
onPressed: () {
106-
vm.cancelDeviceSelection();
107-
Navigator.of(context).pop();
108-
_deviceSelectionDialogOpen = false;
109-
},
110-
child: const Text('Cancel'),
111-
),
112-
],
113115
),
114116
);
115117
// After dialog closes, if a device was selected, explicitly load data now

0 commit comments

Comments
 (0)