Pop dialogs by default when device changes.

This commit is contained in:
Dain Nilsson 2022-06-10 16:02:07 +02:00
parent 3a485b9cf6
commit 141fa419e4
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
16 changed files with 27 additions and 69 deletions

View File

@ -77,10 +77,12 @@ class AboutPage extends ConsumerWidget {
style: TextStyle(decoration: TextDecoration.underline),
),
onPressed: () {
showLicensePage(
context: context,
applicationVersion: version,
);
Navigator.of(context).push(MaterialPageRoute<void>(
builder: (BuildContext context) => const LicensePage(
applicationVersion: version,
),
settings: const RouteSettings(name: 'licenses'),
));
},
),
const Padding(

View File

@ -48,6 +48,7 @@ class DeviceButton extends ConsumerWidget {
showDialog(
context: context,
builder: (context) => const DevicePickerDialog(),
routeSettings: const RouteSettings(name: 'device_picker'),
);
},
),

View File

@ -93,7 +93,10 @@ class MainPageDrawer extends ConsumerWidget {
final nav = Navigator.of(context);
if (shouldPop) nav.pop();
showDialog(
context: context, builder: (context) => const SettingsPage());
context: context,
builder: (context) => const SettingsPage(),
routeSettings: const RouteSettings(name: 'settings'),
);
},
),
DrawerItem(
@ -103,7 +106,10 @@ class MainPageDrawer extends ConsumerWidget {
final nav = Navigator.of(context);
if (shouldPop) nav.pop();
showDialog(
context: context, builder: (context) => const AboutPage());
context: context,
builder: (context) => const AboutPage(),
routeSettings: const RouteSettings(name: 'about'),
);
},
),
],

View File

@ -20,6 +20,18 @@ class MainPage extends ConsumerWidget {
next?.call(context);
},
);
// If the current device changes, we need to pop any open dialogs.
ref.listen<DeviceNode?>(currentDeviceProvider, (_, __) {
Navigator.of(context).popUntil((route) {
return route.isFirst ||
[
'device_picker',
'settings',
'about',
'licenses',
].contains(route.settings.name);
});
});
final deviceData = ref.watch(currentDeviceDataProvider);
if (deviceData == null) {
final node = ref.watch(currentDeviceProvider);

View File

@ -119,12 +119,6 @@ class _AddFingerprintDialogState extends ConsumerState<AddFingerprintDialog>
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
// Prevent over-popping if reset causes currentDevice to change.
Navigator.of(context).popUntil((route) => route.isFirst);
});
final progress = _samples == 0 ? 0.0 : _samples / (_samples + _remaining);
return ResponsiveDialog(

View File

@ -17,11 +17,6 @@ class DeleteCredentialDialog extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop(false);
});
final label = credential.userName;
return ResponsiveDialog(

View File

@ -15,11 +15,6 @@ class DeleteFingerprintDialog extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop(false);
});
final label = fingerprint.label;
return ResponsiveDialog(

View File

@ -28,11 +28,6 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop();
});
final hasPin = widget.state.hasPin;
final isValid = _newPin.isNotEmpty &&
_newPin == _confirmPin &&

View File

@ -39,11 +39,6 @@ class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop();
});
return ResponsiveDialog(
title: const Text('Rename fingerprint'),
actions: [

View File

@ -47,12 +47,6 @@ class _ResetDialogState extends ConsumerState<ResetDialog> {
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
// Prevent over-popping if reset causes currentDevice to change.
Navigator.of(context).popUntil((route) => route.isFirst);
});
return ResponsiveDialog(
title: const Text('Factory reset'),
onCancel: () {

View File

@ -232,11 +232,6 @@ class _ManagementScreenState extends ConsumerState<ManagementScreen> {
@override
Widget build(BuildContext context) {
ref.listen<DeviceNode?>(currentDeviceProvider, (_, __) {
//TODO: This can probably be checked better to make sure it's the main page.
Navigator.of(context).popUntil((route) => route.isFirst);
});
var canSave = false;
final child =
ref.watch(managementStateProvider(widget.deviceData.node.path)).when(

View File

@ -96,12 +96,6 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
//TODO: This can probably be checked better to make sure it's the main page.
Navigator.of(context).popUntil((route) => route.isFirst);
});
final period = int.tryParse(_periodController.text) ?? -1;
final remaining = getRemainingKeySpace(
oathType: _oathType,

View File

@ -15,11 +15,6 @@ class DeleteAccountDialog extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop(false);
});
final label = credential.issuer != null
? '${credential.issuer} (${credential.name})'
: credential.name;

View File

@ -41,11 +41,6 @@ class _ManagePasswordDialogState extends ConsumerState<ManagePasswordDialog> {
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop();
});
final isValid = _newPassword.isNotEmpty &&
_newPassword == _confirmPassword &&
(!widget.state.hasKey || _currentPassword.isNotEmpty);

View File

@ -32,11 +32,6 @@ class _RenameAccountDialogState extends ConsumerState<RenameAccountDialog> {
@override
Widget build(BuildContext context) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop();
});
final credential = widget.credential;
final label = credential.issuer != null

View File

@ -13,11 +13,6 @@ class ResetDialog extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// If current device changes, we need to pop back to the main Page.
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
Navigator.of(context).pop();
});
return ResponsiveDialog(
title: const Text('Factory reset'),
actions: [