handleBackgroundMessage static method

void handleBackgroundMessage(
  1. RemoteMessage message
)

Wire to your background message handler (the @pragma('vm:entry-point') top-level function passed to FirebaseMessaging.onBackgroundMessage). Treated as a silent / background-arrival event.

Note: background handlers run in an isolated Dart isolate; the UniTrack instance there has NO active session unless the app initializes it inside the entry-point. The event will still queue locally and flush once the main isolate revives.

Implementation

static void handleBackgroundMessage(RemoteMessage message) {
  final hasVisible = message.notification != null;
  UniTrack.instance.trackNotification(
    state: hasVisible ? 'background' : 'silent',
    action: 'received',
    title: message.notification?.title,
    body:  message.notification?.body,
    notificationId: _idOf(message),
    data: _safeData(message.data),
  );
}