---
updatedAt: 2026-09-16T05:25:00.000Z
agentTools:
  projectIndex: https://docs.esputnik.com/llms.txt
---

# Flutter Push Handling

# Push Notifications

Complete the common [Flutter setup](https://docs.esputnik.com/reference/flutter-sdk) and the platform-specific [Android](https://docs.esputnik.com/reference/flutter-android-sdk-setup) or [iOS](https://docs.esputnik.com/reference/flutter-ios-sdk-setup) guide first.

Initialize Reteno before calling instance push methods. Subscribing to the push streams does not require initialization, so register those listeners as early as possible: they are broadcast streams and do not replay earlier events.

Pushes to tokens created through the mobile SDK are delivered as FCM Data Messages: the SDK handles the notification display and preserves the push's custom data.

## Request Notification Permission

Use the cross-platform API to request notification permission on iOS and Android 13 or later. The result is also synchronized with Reteno:

```dart
final granted = await Reteno().requestPushPermission();
```

On Android 13 or later, call this only after a Flutter activity is attached; earlier Android versions show no prompt and return the current notification-enabled state.

On iOS 12 or later, provisional authorization is also supported:

```dart
final granted = await Reteno().requestPushPermission(provisional: true);
```

If another package or native code owns the Android permission prompt, synchronize the resulting state with Reteno:

```dart
await Reteno().updatePushPermissionStatus();
```

This method is Android-only and a no-op on iOS. Its `Future<bool>` resolves as soon as the native call is dispatched.

## Get the Initial Notification

Use `getInitialNotification()` once during startup when the application was launched by tapping a push notification:

```dart
final payload = await Reteno().getInitialNotification();

if (payload != null) {
  // Process the notification payload.
}
```

The result is `null` when no launch payload was stored. Reading it clears the payload, so a later call also returns `null`.

On iOS the stored payload is not filtered by the Reteno `es_interaction_id`. Validate it before treating it as Reteno data when the application receives pushes from several providers.

## Listen for Push Events

Every stream below is a broadcast stream. Store and cancel subscriptions with the owning object.

| Stream                                      | Type                                   | Event                                                                  |
| ------------------------------------------- | -------------------------------------- | ---------------------------------------------------------------------- |
| `Reteno.onRetenoNotificationReceived`       | `Stream<Map<String, dynamic>>`         | A notification arrived while the app was in the foreground             |
| `Reteno.onRetenoNotificationClicked`        | `Stream<Map<String, dynamic>>`         | The user tapped a notification                                         |
| `Reteno.onUserNotificationAction`           | `Stream<RetenoUserNotificationAction>` | The user tapped an action button                                       |
| `Reteno.onRetenoNotificationDeleted`        | `Stream<Map<String, dynamic>>`         | Android only: the user dismissed a notification                        |
| `Reteno.onRetenoCustomNotificationReceived` | `Stream<Map<String, dynamic>>`         | Android only: a custom push payload was received                       |
| `Reteno.onRetenoInAppCustomDataReceived`    | `Stream<RetenoInAppCustomData>`        | Android only: custom data arrived from a push-triggered in-app message |

```dart
Reteno.onRetenoNotificationReceived.listen((payload) {
  // Process the notification payload.
});

Reteno.onRetenoNotificationClicked.listen((payload) {
  // Process the notification payload.
});
```

Use `getInitialNotification()` for a terminated-state launch instead of relying on the clicked stream alone.

`onCorePushReceived`, `onCorePushClicked`, and `onCorePushAction` are cross-platform aliases of the first three streams. Subscribe to either name, not both. See [Action Buttons](https://docs.esputnik.com/reference/flutter-action-buttons) for the action model and [In-App Messages](https://docs.esputnik.com/reference/flutter-in-app-messages-lifecycle-callbacks#android-in-app-custom-data) for `RetenoInAppCustomData`.

On iOS these callbacks are independent of the token mode: one native coordinator processes them in all three modes while interoperating with FlutterFire. See [Notification delegate coordination](https://docs.esputnik.com/reference/flutter-ios-sdk-setup#notification-delegate-coordination).

The SDK displays pushes sent from eSputnik itself, including while the app is in the foreground, and this can't be turned off. If your app also shows its own local notifications from `FirebaseMessaging.onMessage`, skip messages whose `data` contains `es_interaction_id` — otherwise the same push appears twice.

## Links in Push Notifications

A link sent in a push is opened by the SDK in the device browser by default. Handling deep links on the Flutter side alone doesn't change that: the link reaches the native SDK first, so the handler has to be registered there — see [iOS Links Handler](https://docs.esputnik.com/reference/links-handler) and [Android push handling](https://docs.esputnik.com/reference/android-push-handling#deeplinks).

## Push Token Handling

Android always handles the FCM token automatically. On iOS, choose the mode that matches the mobile app in eSputnik:

| Mode        | Token owner                                                                                  |
| ----------- | -------------------------------------------------------------------------------------------- |
| `automatic` | The bridge reports the APNs token                                                            |
| `manual`    | The plugin reports the current and refreshed FCM token without replacing Firebase's delegate |
| `external`  | The application reports the FCM token with `setPushToken()`                                  |

The bridge routes only the source that matches the selected mode, so an early APNs callback can never be forwarded as an FCM token. See the [iOS routing guarantees](https://docs.esputnik.com/reference/flutter-ios-sdk-setup#token-routing-guarantees-in-1110).

In `external` mode, send the FCM registration token after initialization and APNs registration, after identifying or changing the user, and whenever Firebase refreshes it:

```dart
await Reteno().setPushToken(fcmToken);
```

Do not pass an APNs token to this method: it is trimmed and rejected only when empty, and the type cannot be inferred. Calling it in `automatic` returns a native mode error. The returned `Future` completes when native processing is dispatched, not when the backend has associated the token with the contact.

See [Select the iOS push token mode](https://docs.esputnik.com/reference/flutter-ios-sdk-setup#7-select-the-ios-push-token-mode) for the complete configuration and refresh listener.

## Android Notification Grouping

Configure grouping after initialization. Assign every eSputnik push notification to a constant group:

```dart
await Reteno().setNotificationGroupingRule(
  const RetenoNotificationGroupingRule.constant('orders'),
);
```

Or derive the group ID from a push payload field:

```dart
await Reteno().setNotificationGroupingRule(
  const RetenoNotificationGroupingRule.byPayloadKey(
    'orderNumber',
    fallbackGroupId: 'orders',
  ),
);
```

If the key is missing or empty, the fallback is used; without a fallback the notification is not grouped.

Pass `null` to disable grouping:

```dart
await Reteno().setNotificationGroupingRule(null);
```

Payload keys and group IDs are trimmed, and a rule with no non-empty key or fallback throws `ArgumentError`.

The native plugin persists the rule, so it also applies when a push arrives without a running Flutter engine. The rule sets the notification group key but does not create a group summary notification; the application is responsible for summary behavior.

This API has no effect on iOS.

## Integration Diagnostics

Run diagnostics after initialization:

```dart
final issues = await Reteno().diagnose();
```

The method can return these codes:

| Code                                  | Platform     | Meaning                                                            |
| ------------------------------------- | ------------ | ------------------------------------------------------------------ |
| `SDK_NOT_INITIALIZED`                 | Android, iOS | Reteno has not been initialized                                    |
| `NOTIFICATIONS_DISABLED`              | Android      | Notifications are disabled in system settings                      |
| `PUSH_PERMISSION_DENIED`              | Android, iOS | Notification permission was denied; Android API 33+ only           |
| `PUSH_PERMISSION_NOT_DETERMINED`      | iOS          | The permission prompt has not been resolved                        |
| `REMOTE_NOTIFICATIONS_NOT_REGISTERED` | iOS          | Permission was granted, but APNs registration is incomplete        |
| `FCM_MESSAGING_SERVICE_MISSING`       | Android      | No active `MESSAGING_EVENT` handler                                |
| `RETENO_MESSAGING_SERVICE_MISSING`    | Android      | No Reteno handler among the messaging services                     |
| `FCM_MESSAGING_SERVICE_CONFLICT`      | Android      | Multiple application-level `MESSAGING_EVENT` services are declared |
| `FCM_TOKEN_MISSING`                   | Android      | Firebase returned no current FCM token                             |
| `FCM_TOKEN_FETCH_FAILED`              | Android      | Fetching the FCM token failed                                      |

An empty list means that the plugin's local checks passed. It does not verify the access key, bundle or application ID, provider credentials, the iOS App Group and service extension, token-mode selection, or actual delivery. On Android, `SDK_NOT_INITIALIZED` reflects bridge state only; native initialization continues asynchronously.

APNs registration is asynchronous, so a diagnostic call made right after permission is granted can temporarily return `REMOTE_NOTIFICATIONS_NOT_REGISTERED`.

## End-to-End Troubleshooting

If eSputnik says that a contact has no app token, or a test push does not arrive:

1. Initialize Reteno on application startup before calling other Reteno APIs.
2. Request push permission and resolve every persistent diagnostics code.
3. Identify the target contact with `Reteno().setUserAttributes(userExternalId: ...)`.
4. Verify that the eSputnik mobile app, access key, bundle/application ID, and provider belong to the same environment.
5. Send a test notification from eSputnik to a physical device.

On Android, also verify that:

* the device is API 26 or later and has working Google Play services;
* `google-services.json` belongs to the current `applicationId`;
* the merged manifest has exactly one effective `MESSAGING_EVENT` service;
* a custom service follows the [advanced Android setup](https://docs.esputnik.com/reference/flutter-android-sdk-setup#custom-firebasemessagingservice).

On iOS, also verify that:

* Firebase is initialized before Reteno in `manual` and `external`;
* the App Group and Notification Service Extension are signed and embedded correctly;
* APNs credentials are stored in eSputnik, or the APNs key is stored in Firebase for FCM;
* for direct APNs, the build signing and the eSputnik provider use the same sandbox or production environment;
* the selected token mode matches the provider configured in eSputnik;
* in `external`, `setPushToken()` runs after APNs registration, after identification, and on every refresh;
* the app keeps the Flutter-first delegate registration order described in the [iOS guide](https://docs.esputnik.com/reference/flutter-ios-sdk-setup#notification-delegate-coordination).