Configuring push notifications (Flutter)
Prerequisites
Firebase Cloud Messaging
Google Firebase Cloud Messaging is necessary to handle push notifications sent from Synerise.
- Follow the instructions in this article and integrate the Firebase plugin with your application.
- Follow the instructions in this article and integrate cloud messaging in your application.
- Integrate Firebase with Synerise. See Integration section.
Setting up - Android
Requirements
-
After configuring Firebase, add the
google-services.json
file to your project. -
Add the google-services dependency to your project’s
build.gradle
file.dependencies { ... classpath 'com.google.gms:google-services:4.3.3' ... }
Setting up - iOS
Requirements
-
Configure handling Push Notifications in your application. See Apple Notifications.
-
After configuring Firebase, add the
GoogleService-Info.plist
file to your project. -
Make sure your
Info.plist
file contains the following snippet:
<false/><key>FirebaseAppDelegateProxyEnabled</key><false/>
Extensions for push notifications
Notification Service Extension
Synerise Notification Service Extension is an object that adds the notification functionality to the SDK.
It implements the following operations:
- Decrypting Simple Push communication data (if encryption is enabled).
- Tracking events from Simple Push communication.
- Adding action buttons to Simple Push communication (if the communication contains any).
- Improving the appearance of Simple Push communication (Rich Media - Single Image) with an image thumbnail.
Notification Service Extension should be implemented in the native part of the application. Follow the instructions in this article.
Rich Media Notification Content Extensions
Synerise Rich Media Notification Content Extension is an object that allows rendering your own appearance of a push notification when the notification is expanded (by tapping the notification).
Synerise Rich Media Notification Content Extensions should be implemented in the native part of the application. Follow the instructions in this article.
Set up Firebase Cloud Messaging for Synerise SDK
The following code example explains how to implement Firebase Cloud Messaging integration with Synerise:
Request for permission from the user.
await FirebaseMessaging.instance.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
Set presentation options for foreground state.
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
sound: true,
badge: true
);
Set background message handler.
FirebaseMessaging.onBackgroundMessage(backgroundHandlerForFCM);
@pragma('vm:entry-point')
Future<void> backgroundHandlerForFCM(RemoteMessage message) async {
await Firebase.initializeApp();
await Synerise.initializer()
.withClientApiKey("YOUR_PROFILE_API_KEY")
.withBaseUrl("YOUR_API_BASE_URL")
.withDebugModeEnabled(false)
.init();
await Synerise.notifications.handleNotification(message.toMap());
Get Firebase FCM token and implement listeners so our SDK can receive the Firebase token that is required to deliver push notifications from Synerise.
FirebaseMessaging.instance.getToken().then((value) {
if (value != null) {
Synerise.notifications.registerForNotifications(value, true);
}
});
FirebaseMessaging.instance.onTokenRefresh.listen((event) {
FirebaseMessaging.instance.getToken().then((value) {
if (value != null) {
Synerise.notifications.registerForNotifications(value, true);
}
});
});
Make sure that the Firebase FCM token is always up-to-date by implementing the onRegistrationRequired() method.
Synerise.notifications.listener((listener) {
listener.onRegistrationRequired = () {
Synerise.notifications.registerForNotifications(firebaseToken!, true);
};
});
Configure Notification Encryption
Android
See Configure Notification Encryption.
iOS
See Synerise Notification Service Extension and Configure Notification Encryption.
Application implementation
In the application, you must set encryption
to true
in the SDK initializer or in the SDK settings.
// WARNING: This option must be configured before Synerise SDK is initialized!
Synerise.settings.notifications.encryption = true;
Handling incoming push notifications
Synerise payload
The following code introduces how to handle push notifications:
FirebaseMessaging.onMessage.listen((RemoteMessage message,) {
Synerise.notifications.handleNotification(message.toMap());
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
Synerise.notifications.handleNotificationClick(message.toMap());
});
Handling actions from push notifications
- Read more about types of actions in campaigns
- Read more about handling actions from push notifications
Additional in-app alert from push notifications
The Flutter SDK on iOS devices can display an additional alert in the application after a push notification is received. See this article to read more about this feature.

Limitations compared to native platforms
Due to platform limitations, not all notification functionalities may work as in native SDKs.
- iOS only: Native-configured button from a Simple Push campaign always invokes the default action (if configured) or displays an in-app alert with buttons to choose.