'Flutter Push to another page if a critical error occurs

Writing on the page can not be converted to the page display the error message

... .... flutter ... ... dart

.......... application restart ..................

my code...

main

Future<void> main() async {
  runZonedGuarded(() {
    WidgetsFlutterBinding.ensureInitialized();

    FlutterError.onError = (FlutterErrorDetails errorDetails) {
      print('This is an error on the Flutter SDK');
      // print(errorDetails.exception);
      print('-----');
      // print(errorDetails.stack);
    };

    runApp(const MyApp());
  }, (error, stackTrace) {
    print('This is a pure Dart error');
    // print(error);
    print('-----');
    // print(stackTrace);
  });
}
myApp

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        builder: (BuildContext context, Widget? widget) {
          ErrorWidget.builder =
              (FlutterErrorDetails errorDetails) => const ErrorPage();
          return widget!;
        },
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        debugShowCheckedModeBanner: false,
        home: const MyApp());
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source