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?
A StackTrace is intended to convey information to the user about the call sequence that triggered an exception. These objects are created by the runtime, it is not possible to create them programmatically.
These frames represent a moment during an application’s execution. A stack frame is information about a method or function that your code called. So the Java stack trace is a list of frames that starts at the current method and extends to when the program started. Sometimes there’s confusion between a stack and the Stack.
From the Analyze menu, click Analyze Stack Trace . Paste the stack trace text into the Analyze Stack Trace window and click OK . Android Studio opens a new <Stacktrace> tab with the stack trace you pasted under the Run window.
To read this stack trace, start at the top with the Exception's type - ArithmeticException and message The denominator must not be zero.
Get a Stack Trace Using the Thread Class We can obtain a stack trace from a thread by calling the getStackTrace () method on the Thread instance. It returns an array of StackTraceElement, from which details about stack frames of the thread can be found.
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
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