Wrap app in zone guard

This commit is contained in:
OmarHatem 2022-11-23 18:06:09 +02:00
parent 9b32c9c956
commit 38da6e73d4

View file

@ -42,9 +42,16 @@ final navigatorKey = GlobalKey<NavigatorState>();
final rootKey = GlobalKey<RootState>(); final rootKey = GlobalKey<RootState>();
Future<void> main() async { Future<void> main() async {
try {
await runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// FlutterError.onError = ;
// Isolate.current.addErrorListener(RawReceivePort((pair) async {
// final List<dynamic> errorAndStacktrace = pair;
// }).sendPort);
final appDir = await getApplicationDocumentsDirectory(); final appDir = await getApplicationDocumentsDirectory();
await Hive.close(); await Hive.close();
Hive.init(appDir.path); Hive.init(appDir.path);
@ -130,7 +137,7 @@ Future<void> main() async {
secureStorage: secureStorage, secureStorage: secureStorage,
initialMigrationVersion: 17); initialMigrationVersion: 17);
runApp(App()); runApp(App());
} catch (e, stacktrace) { }, (error, stackTrace) {
runApp(MaterialApp( runApp(MaterialApp(
debugShowCheckedModeBanner: true, debugShowCheckedModeBanner: true,
home: Scaffold( home: Scaffold(
@ -138,10 +145,10 @@ Future<void> main() async {
margin: margin:
EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20), EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20),
child: Text( child: Text(
'Error:\n${e.toString()}\nStacktrace: $stacktrace', 'Error:\n${error.toString()}\nStacktrace: $stackTrace',
style: TextStyle(fontSize: 22), style: TextStyle(fontSize: 22),
))))); )))));
} });
} }
Future<void> initialSetup( Future<void> initialSetup(