error method

  1. @override
Future<void> error({
  1. dynamic error,
  2. StackTrace? stackTrace,
  3. LogEvent? event,
})
override

Records an error or a structured event with an error to Firebase Crashlytics.

Errors are logged with their associated stack traces. If an event is provided, additional context is included in the report.

error - the error to log. stackTrace - the stack trace associated with the error. event - an optional LogEvent providing additional context for the error.

Implementation

@override
Future<void> error(
    {dynamic error, StackTrace? stackTrace, LogEvent? event}) async {
  try {
    if (shouldLog(event: event)) {
      developer.log(
        'Reporting error to Firebase Crashlytics',
        name: 'FirebaseCrashlyticsLogStrategy',
      );
      if (event != null && event is FirebaseCrashlyticsLogEvent) {
        FirebaseCrashlytics.instance
            .recordError(error, stackTrace, reason: event.eventMessage);
      } else {
        FirebaseCrashlytics.instance.recordError(error, stackTrace);
      }
    }
  } catch (e, stack) {
    developer.log(
      'Error during error handling in Firebase Crashlytics Strategy',
      name: 'FirebaseCrashlyticsLogStrategy',
      error: e,
      stackTrace: stack,
    );
  }
}