mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-06 19:09:30 +00:00
CW-695: Fix Zone Mismatch Error Triggered By Restoring Backup (#1651)
Some checks are pending
Cache Dependencies / test (push) Waiting to run
Some checks are pending
Cache Dependencies / test (push) Waiting to run
* Fix: Zone mismatch error triggered by restoring backup * fix: Adjust check for reinitializing
This commit is contained in:
parent
0b06ad3a07
commit
3869a71bd1
2 changed files with 51 additions and 32 deletions
|
@ -48,11 +48,14 @@ final rootKey = GlobalKey<RootState>();
|
||||||
final RouteObserver<PageRoute<dynamic>> routeObserver = RouteObserver<PageRoute<dynamic>>();
|
final RouteObserver<PageRoute<dynamic>> routeObserver = RouteObserver<PageRoute<dynamic>>();
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
|
await runAppWithZone();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> runAppWithZone() async {
|
||||||
bool isAppRunning = false;
|
bool isAppRunning = false;
|
||||||
|
|
||||||
await runZonedGuarded(() async {
|
await runZonedGuarded(() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
FlutterError.onError = ExceptionHandler.onError;
|
FlutterError.onError = ExceptionHandler.onError;
|
||||||
|
|
||||||
/// A callback that is invoked when an unhandled error occurs in the root
|
/// A callback that is invoked when an unhandled error occurs in the root
|
||||||
|
@ -62,42 +65,14 @@ Future<void> main() async {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
await initializeAppAtRoot();
|
||||||
await setDefaultMinimumWindowSize();
|
|
||||||
|
|
||||||
await CakeHive.close();
|
|
||||||
|
|
||||||
await initializeAppConfigs();
|
|
||||||
|
|
||||||
runApp(App());
|
runApp(App());
|
||||||
|
|
||||||
isAppRunning = true;
|
isAppRunning = true;
|
||||||
}, (error, stackTrace) async {
|
}, (error, stackTrace) async {
|
||||||
if (!isAppRunning) {
|
if (!isAppRunning) {
|
||||||
runApp(
|
runApp(
|
||||||
MaterialApp(
|
TopLevelErrorWidget(error: error, stackTrace: stackTrace),
|
||||||
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),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
Future<void> initializeAppConfigs() async {
|
||||||
setRootDirFromEnv();
|
setRootDirFromEnv();
|
||||||
final appDir = await getAppDir();
|
final appDir = await getAppDir();
|
||||||
|
@ -338,3 +319,41 @@ class _HomeState extends State<_Home> {
|
||||||
return const SizedBox.shrink();
|
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();
|
final data = await file.readAsBytes();
|
||||||
|
|
||||||
await backupService.importBackup(data, password);
|
await backupService.importBackup(data, password);
|
||||||
await main();
|
await initializeAppAtRoot(reInitializing: true);
|
||||||
|
|
||||||
final store = getIt.get<AppStore>();
|
final store = getIt.get<AppStore>();
|
||||||
ReactionDisposer? reaction;
|
ReactionDisposer? reaction;
|
||||||
|
|
Loading…
Reference in a new issue