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

Viewed 1007

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?

1 Answers

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

Related