mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
CW-695: Fix Zone Mismatch Error Triggered By Restoring Backup (#1651)
* Fix: Zone mismatch error triggered by restoring backup * fix: Adjust check for reinitializing
This commit is contained in:
+50
-31
@@ -48,11 +48,14 @@ final rootKey = GlobalKey<RootState>();
|
||||
final RouteObserver<PageRoute<dynamic>> routeObserver = RouteObserver<PageRoute<dynamic>>();
|
||||
|
||||
Future<void> main() async {
|
||||
await runAppWithZone();
|
||||
}
|
||||
|
||||
Future<void> runAppWithZone() async {
|
||||
bool isAppRunning = false;
|
||||
|
||||
await runZonedGuarded(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
FlutterError.onError = ExceptionHandler.onError;
|
||||
|
||||
/// A callback that is invoked when an unhandled error occurs in the root
|
||||
@@ -62,42 +65,14 @@ Future<void> main() async {
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
await setDefaultMinimumWindowSize();
|
||||
|
||||
await CakeHive.close();
|
||||
|
||||
await initializeAppConfigs();
|
||||
await initializeAppAtRoot();
|
||||
|
||||
runApp(App());
|
||||
|
||||
isAppRunning = true;
|
||||
}, (error, stackTrace) async {
|
||||
if (!isAppRunning) {
|
||||
runApp(
|
||||
MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
scrollBehavior: AppScrollBehavior(),
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Error:\n${error.toString()}',
|
||||
style: TextStyle(fontSize: 22),
|
||||
),
|
||||
Text(
|
||||
'Stack trace:\n${stackTrace.toString()}',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
TopLevelErrorWidget(error: error, stackTrace: stackTrace),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -105,6 +80,12 @@ Future<void> main() async {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> initializeAppAtRoot({bool reInitializing = false}) async {
|
||||
if (!reInitializing) await setDefaultMinimumWindowSize();
|
||||
await CakeHive.close();
|
||||
await initializeAppConfigs();
|
||||
}
|
||||
|
||||
Future<void> initializeAppConfigs() async {
|
||||
setRootDirFromEnv();
|
||||
final appDir = await getAppDir();
|
||||
@@ -338,3 +319,41 @@ class _HomeState extends State<_Home> {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
class TopLevelErrorWidget extends StatelessWidget {
|
||||
const TopLevelErrorWidget({
|
||||
required this.error,
|
||||
required this.stackTrace,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final Object error;
|
||||
final StackTrace stackTrace;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
scrollBehavior: AppScrollBehavior(),
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Error:\n${error.toString()}',
|
||||
style: TextStyle(fontSize: 22),
|
||||
),
|
||||
Text(
|
||||
'Stack trace:\n${stackTrace.toString()}',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ abstract class RestoreFromBackupViewModelBase with Store {
|
||||
final data = await file.readAsBytes();
|
||||
|
||||
await backupService.importBackup(data, password);
|
||||
await main();
|
||||
await initializeAppAtRoot(reInitializing: true);
|
||||
|
||||
final store = getIt.get<AppStore>();
|
||||
ReactionDisposer? reaction;
|
||||
|
||||
Reference in New Issue
Block a user