How to see Dart code stack trace instead of Java code stack trace in Crashlytics/Flutter (Android)

783

I added this lines to my main.dart to get the Dart StackTrace:

FlutterError.onError = (error) => flutterErrorHandler(error);

runZonedGuarded<Future<void>>(
    () async => runApp(
      YourAppWidget(),
    ),
    (error, strack) async {
      debugPrint(error.toString());
      // Whenever an error occurs, call the `reportCrash`
      // to send Dart errors to Crashlytics
      Crashlytics.instance.recordError(error, strack);
    },
  );
void flutterErrorHandler(FlutterErrorDetails details) {
  FlutterError.dumpErrorToConsole(details);

  // Report to the application zone to report to Crashlytics.
  Zone.current.handleUncaughtError(details.exception, details.stack);
}

For more details see: https://pub.dev/packages/firebase_crashlytics

Share:
783
Mark
Author by

Mark

Computer person, tree hugger, father (not necessarily in that order)

Updated on December 21, 2022

Comments

  • Mark
    Mark over 1 year

    We are using the firebase_crashlytics plugin for Flutter to get error reports in Crashlytics. Unfortunately for Android, only the non-fatal issues show a proper Dart code stack trace. The fatal issues only show Java code stack trace which makes them very hard to debug.

    Is there any way to get proper Dart code stack traces for fatal issues as well?

  • Mark
    Mark almost 4 years
    Thank you, I will try this out.
  • Purushotam Kumar
    Purushotam Kumar over 3 years
    Is the suggested answer working? if not what are the other options i can go with?