I couldn't understand the crashlytics documentation for runZonedGuarded usage
So do I need it or not?
https://firebase.flutter.dev/docs/crashlytics/usage/#zoned-errors
June 2023 Answer:
No, you don't need runZonedGuarded for Crashlytics anymore.
Using runZonedGuarded for Crashlytics is deprecated. You can see that in this commit where all references to runZonedGuarded were replaced:
https://github.com/firebase/flutterfire/commit/8a0caa05d5abf6fef5bf0e654654dcd0b6ec874a
Also note that the current official documentation doesn't mention runZonedGuarded anymore: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=flutter
The recommended way is this:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = (errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
// Pass all uncaught asynchronous errors that aren't handled by the Flutter framework to Crashlytics
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};
runApp(MyApp());
}
Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With