Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crashlytics and runZonedGuarded

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

like image 752
amorenew Avatar asked Oct 18 '25 05:10

amorenew


1 Answers

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!

like image 74
Johannes Fahrenkrug Avatar answered Oct 20 '25 04:10

Johannes Fahrenkrug