improve error handling (#1451)

This commit is contained in:
Omar Hatem 2024-05-14 04:27:16 +03:00 committed by GitHub
parent e92e8df3aa
commit c12b4f5ff6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 32 deletions

View file

@ -47,6 +47,7 @@ final rootKey = GlobalKey<RootState>();
final RouteObserver<PageRoute<dynamic>> routeObserver = RouteObserver<PageRoute<dynamic>>();
Future<void> main() async {
bool isAppRunning = false;
await runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
@ -67,31 +68,35 @@ Future<void> main() async {
await initializeAppConfigs();
runApp(App());
isAppRunning = true;
}, (error, stackTrace) async {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
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),
),
],
if (!isAppRunning) {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
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),
),
],
),
),
),
),
),
),
);
);
}
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace));
});