Add workaround for device picker losing focus on device change.

This commit is contained in:
Dain Nilsson 2022-07-06 16:56:34 +02:00
parent 38528c81ae
commit f81d2d06bc
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8

View File

@ -40,9 +40,48 @@ class _HiddenDevicesNotifier extends StateNotifier<List<String>> {
} }
} }
class DevicePickerDialog extends ConsumerWidget { class DevicePickerDialog extends StatefulWidget {
const DevicePickerDialog({super.key}); const DevicePickerDialog({super.key});
@override
State<StatefulWidget> createState() => _DevicePickerDialogState();
}
class _DevicePickerDialogState extends State<DevicePickerDialog> {
late FocusScopeNode _focus;
@override
void initState() {
super.initState();
_focus = FocusScopeNode();
}
@override
void dispose() {
_focus.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// This keeps the focus in the dialog, even if the underlying page
// changes as it does when a new device is selected.
return FocusScope(
node: _focus,
autofocus: true,
onFocusChange: (focused) {
if (!focused) {
_focus.requestFocus();
}
},
child: const _DevicePickerContent(),
);
}
}
class _DevicePickerContent extends ConsumerWidget {
const _DevicePickerContent();
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final hidden = ref.watch(_hiddenDevicesProvider); final hidden = ref.watch(_hiddenDevicesProvider);