Push notifications - Flutter

When your app receives a push notification for Experiences SDK content, hand its payload to the SDK, which starts playback of the content the notification points to. Check the payload with canHandlePushNotification, then pass the same payload to handleNotificationPayload.

Both methods are on the BlazeSDK class. Call them after the SDK initializes. See Getting started Flutter.

Handle a push notification

Pass the notification's custom data, such as RemoteMessage.data from firebase_messaging.

Future<void> handleBlazeNotification(Map<String, dynamic> data) async {
  try {
    final canHandle = await BlazeSDK.canHandlePushNotification(data);
    if (canHandle) {
      await BlazeSDK.handleNotificationPayload(payload: data);
    }
  } catch (e) {
    debugPrint('BlazeSDK notification error: $e');
  }
}

Methods

canHandlePushNotification

Checks whether the SDK can handle a notification's payload.

static Future<bool> canHandlePushNotification(Map<String, dynamic> payload)

Parameters:

  • payload: A map representing the payload to be checked. The keys and values are specific to the notification's data structure.

Returns: A Future that completes with true if the SDK can handle the payload, otherwise false.

final canHandle = await BlazeSDK.canHandlePushNotification(payload);

handleNotificationPayload

Handles a notification's payload.

static Future<void> handleNotificationPayload({
  required Map<String, dynamic> payload,
  String? sourceId,
})

Parameters:

  • payload: A map representing the payload to be handled. The keys and values are specific to the notification's data structure.
  • sourceId: An optional entry point identifier. The SDK surfaces it in the sourceId field of the delegate callbacks triggered by the playback this notification starts.

Returns: A Future that completes when the SDK finishes processing the payload, or throws an error if processing fails.

try {
  await BlazeSDK.handleNotificationPayload(
    payload: payload,
    sourceId: 'push-notification',
  );
} catch (e) {
  // Handle error
}

sourceId and the named payload parameter are available from Flutter SDK 1.20.0. Before 1.20.0, the method took the payload as a positional argument: BlazeSDK.handleNotificationPayload(payload).


Did this page help you?