mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +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>>();
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue