fatal method
Marks an error as fatal and records it to Firebase Crashlytics.
Fatal errors are treated as critical failures that should be prominently flagged in Crashlytics. Additional context can be provided through a LogEvent.
error
- the critical error to log.
stackTrace
- the stack trace associated with the critical error.
event
- an optional LogEvent providing additional context for the critical error.
Implementation
@override
Future<void> fatal(
{dynamic error, StackTrace? stackTrace, LogEvent? event}) async {
try {
if (shouldLog(event: event)) {
developer.log(
'Recording fatal error to Firebase Crashlytics',
name: 'FirebaseCrashlyticsLogStrategy',
);
if (event != null && event is FirebaseCrashlyticsLogEvent) {
FirebaseCrashlytics.instance.recordError(error, stackTrace,
reason: event.eventMessage, fatal: true);
} else {
FirebaseCrashlytics.instance
.recordError(error, stackTrace, fatal: true);
}
}
} catch (e, stack) {
developer.log(
'Error during fatal error handling in Firebase Crashlytics Strategy',
name: 'FirebaseCrashlyticsLogStrategy',
error: e,
stackTrace: stack,
);
}
}