diff --git a/lib/widgets/settings/backup_restore_page.dart b/lib/widgets/settings/backup_restore_page.dart index 52b3df1..45cb1a7 100644 --- a/lib/widgets/settings/backup_restore_page.dart +++ b/lib/widgets/settings/backup_restore_page.dart @@ -207,6 +207,9 @@ class BackupRestorePage extends StatelessWidget { Future _confirmFileImport( BuildContext context, AppLocalizations localizations, BackupFileEntry entry) async { + final backupService = context.read(); + final settingsService = context.read(); + final appsService = context.read(); showDialog( context: context, builder: (dialogContext) => AlertDialog( @@ -220,7 +223,11 @@ class BackupRestorePage extends StatelessWidget { TextButton( onPressed: () async { Navigator.of(dialogContext).pop(); - _import(context, localizations, entry.file); + try { + await backupService.importBackup(entry.file); + settingsService.reload(); + await appsService.refreshState(); + } catch (_) {} }, child: const Text("Import"), ), @@ -228,43 +235,4 @@ class BackupRestorePage extends StatelessWidget { ), ); } - - Future _import(BuildContext context, AppLocalizations localizations, File file) async { - try { - await context.read().importBackup(file); - if (context.mounted) { - context.read().reload(); - await context.read().refreshState(); - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text("Import Success"), - content: Text(localizations.importSuccess), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text("OK"), - ), - ], - ), - ); - } - } catch (e) { - if (context.mounted) { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text("Import Failed"), - content: Text(localizations.importError(e.toString())), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text("OK"), - ), - ], - ), - ); - } - } - } }