I'm trying to use firebase_crashlytics lib with my Flutter project, the problem is that Flutter never crashes, I can throw exceptions in the code, but all exceptions in dart are considered non-fatal exceptions. Those will be reported normally to the console, but I wanted Flutter, native, and unhandled exceptions to be considered fatal exceptions.
I wanted one of the following:
- Crash the app when I have an unexpected exception (close the app with "not responding")
- Report fatal exception to firebase console
- A work around?
My main.dart code:
Future main() async {
runZoned<Future<void>>(() async {
await DotEnv().load('.env');
setupNotifications();
FlutterError.onError = Crashlytics.instance.recordFlutterError;
runApp(MyApp());
}, onError: Crashlytics.instance.recordError);
}
What I already tried to do:
SystemChannels.platform.invokeMethod('SystemNavigator.pop');It works, but not really user friendly- Call kotlin function that tried to crash the app via
MethodChannel, didn't work.
Things I could probably do:
- Call a
toastto notify the user that something went wrong - Show a pop-up notifying the user that something went wrong and close the app
- Just close the app
- Try to load the initial state of the application main screen