fatal method

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

Marks an error as fatal and records it to Firebase Analytics, ensuring it is flagged as a critical incident.

error - The critical error to log as fatal. stackTrace - The stack trace associated with the critical error, providing detailed context for system failures. event - An optional LogEvent providing additional context for the critical error, aiding in root cause analysis.

Implementation

@override
Future<void> fatal({error, StackTrace? stackTrace, LogEvent? event}) async {
  try {
    if (shouldLog(event: event)) {
      developer.log(
        '>>═══════════════════════FIREBASE ANALYTICS LOG STRATEGY [FATAL]═══════════════════════<<',
        name: 'FirebaseAnalyticsLogStrategy',
      );
      if (event != null) {
        final FirebaseAnalyticsLogEvent analyticsEvent =
            event as FirebaseAnalyticsLogEvent;
        _analytics.logEvent(
          name: 'fatal_error',
          parameters: {
            'param_message': error.toString(),
            'param_error': stackTrace?.toString() ?? 'no_exception_provided',
            'param_event_type': analyticsEvent.eventName,
          },
        );
      } else {
        _analytics.logEvent(
          name: 'FATAL: $error',
        );
      }
    }
  } catch (e, stack) {
    developer.log(
      'Error during Firebase Analytics fatal error handling: $e',
      name: 'FirebaseAnalyticsLogStrategy',
      error: e,
      stackTrace: stack,
    );
  }
}