MobilePush Flutter Plugin

Use the Flutter Plugin to integrate the MobilePush SDK into your Flutter applications.

To install the Flutter plugin, add the plugin to your application using Pub by running the following command.

The steps described in this section can vary depending on your app and the Flutter version it's using.

Navigate to android/build.gradle and add the MobilePush SDK repository.

Navigate to android/app/build.gradle and update the dependencies section to include the marketingcloudsdk dependency.

In your app's build.gradle file, ensure that the following SDK version parameters are set to the following versions.

ParameterVersion
compileSdk or compileSdkVersion34
minSdkVersion21

Ensure the org.jetbrains.kotlin.android or org.jetbrains.kotlin:kotlin-gradle-plugin specified is equal to or above 1.9.10.

Depending on your Flutter implementation, the location for specifying the Kotlin version can differ. You can specify the Kotlin version in either android/build.gradle or android/settings.gradle.

To enable push support for the Android platform, you must provide your Firebase Cloud Messaging (FCM) credentials by including the google-services.json file in your config.xml file.

  1. Download the google-services.json file from your application's Firebase console and place it in your project's android/app directory

  2. Include the Google Services plugin in your android/settings.gradle file.

    If pluginManagement isn’t present in your settings.gradle, add this dependency in android/build.gradle under the buildscript section. If there’s no buildscript section, create it.

  3. Apply the plugin in the android/app/build.gradle file by updating the plugins section.

    This step can vary depending on your implementation.

    If the plugins section doesn’t exist in your android/app/build.gradle file, add the following code at the end of the file.

If MainApplication.kt isn't present in your app, create it by extending the FlutterApplication class. Additionally, update AndroidManifest.xml.

Update MainApplication.kt in your app.

Update AndroidManifest.xml to declare the notification permission.

The SDK doesn’t automatically present URLs from these sources.

  • CloudPages URLs from push notifications
  • OpenDirect URLs from push notifications
  • Action URLs from in-app messages

To handle URLs from push notifications, follow these steps.

Navigate to MainApplication.kt and update setNotificationCustomizationOptions, as shown in the following examples.

  1. Add imports.

  2. Update setNotificationCustomizationOptions in MarketingCloudConfig.

  3. Implement the following methods in MainApplication.kt.

To handle URLs from in-app messages, set the setUrlHandler in MarketingCloudConfig as shown in the following example.

Additionally, review the additional documentation on URL Handling for Android.

If you encounter errors related to Java sealed classes or dexing, you must add the r8 dependency to your app. For more information about this error, see Google's IssueTracker.

To add the r8 dependency, update your app's settings.gradle file.

If you don't have pluginManagement in your settings.gradle file, update the buildscript.dependencies section of the android/build.gradle file.

Enable push notifications in your target’s Capabilities settings in Xcode.

Enable Push

  1. Navigate to the YOUR_APP/ios directory and open Runner.xcworkspace.

  2. To configure the SDK and enable push, update AppDelegate.

The SDK doesn’t automatically present URLs from these sources.

  • CloudPages URLs from push notifications
  • OpenDirect URLs from push notifications
  • Action URLs from in-app messages

To handle URLs from push notifications, follow these steps.

  1. Set the setURLHandlingDelegate.
  2. Implement the URLHandlingDelegate.

To set the URLHandlingDelegate, update the AppDelegate as shown in the following example.

Implement the URLHandlingDelegate in AppDelegate, as shown in the following example.

Also review the additional documentation on URL Handling

Rich notifications include images, videos, titles and subtitles from the MobilePush app, and mutable content. Mutable content can include personalization in the title, subtitle, or body of your message.

  1. In Xcode, click File
  2. Click New
  3. Click Target
  4. Select Notification Service Extension
  5. Name and save the new extension

This service extension checks for a "_mediaUrl" element in request.content.userInfo. If it's present, the extension attempts to download media from the URL, creates a thumbnail-size version, and then adds the attachment. Additionally, the service extension also checks for a "_mediaAlt" element in request.content.userInfo. If this key is found, the service extension uses the element for the body text, in case there are any problems downloading or creating the media attachment.

A service extension can time out when it's unable to download media. In the following example, the service extension delivers the original content but replaces the body text with the value from "_mediaAlt".

If you encounter a cycle error while enabling rich notifications, see Resolve Cycle Errors in Flutter Xcode Projects.

If you encounter a cycle error in your Flutter Xcode project after adding a Notification Service Extension, follow these steps to fix it.

  1. Navigate to YOUR_APP_TARGET in Xcode.
  2. With your app target selected, go to the Build Phases tab.
  3. Find Embed Foundation Extension.
  4. Drag and position it above both Thin Binary and Embed Pods Frameworks.

Reordering the build phases resolves the cycle error.

Kind: Global class

The current state of the pushEnabled flag in the native MobilePush SDK.

Kind: Static method of SFMCSdk

Returns: Future<bool?> - A future to the nullable boolean representation of whether push is enabled.

See Also

Enables push messaging in the native MobilePush SDK.

Kind: Static method of SFMCSdk

See Also

Disables push messaging in the native MobilePush SDK.

Kind: Static method of SFMCSdk

See Also

This method returns the token used by Marketing Cloud Engagement to send push messages to the device.

Kind: Static method of SFMCSdk

Returns: Future<String?> - A future to the nullable system token string.

See Also

Returns the maps of attributes set in the registration.

Kind: Static method of SFMCSdk

Returns: Future<Map<String, String>> - A future to the string key-value map of attributes set in the registration.

See Also

Sets the value of an attribute in the registration.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
keystringThe name of the attribute to be set in the registration.
valuestringThe value of the key attribute to be set in the registration.

Clears the value of an attribute in the registration.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
keystringThe name of the attribute whose value must be cleared from the registration.

Adds a tag to the list of tags in the registration.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
tagstringThe tag to be added to the registration.

Removes a tag from the list of tags in the registration.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
tagstringThe tag to be removed from the registration.

Returns the list of tags currently set in the registration.

Kind: Static method of SFMCSdk

Returns: Future<List<String>> - A future to the list of strings representing the tags currently set in the registration.

See Also

Sets the contact key for the device's user.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
contactKeystringThe contact key to be set for the device's user.

Returns the contact key associated with the device's user.

Kind: Static method of SFMCSdk

Returns: Future<String?> - A future to the nullable string representation of the contact key associated with the device's user.

See Also

Enables verbose logging within the native MobilePush SDK and Unified SFMC SDK.

Kind: Static method of SFMCSdk

See Also

Disables verbose logging within the native MobilePush SDK.

Kind: Static method of SFMCSdk

See Also

Instructs the native SDK to log the SDK state to the native logging system (Logcat for Android and Xcode or Console for iOS). The Engagement Support team requests for the SDK state logs during support calls as they can help diagnose most issues.

Kind: Static method of SFMCSdk

See Also

This method helps to track events, which could result in actions such as an InApp Message being displayed.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
eventCustomEvent | EngagementEvent | SystemEvent | CartEvent | OrderEvent | CatalogObjectEventThe event to track.

Returns the deviceId used by Engagement to send push messages to the device.

Kind: Static method of SFMCSdk

Returns: Future<String?> - A future to the device Id.

See Also

Enables or disables analytics in the MobilePush SDK.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
analyticsEnabledbooleanA flag indicating whether to enable analytics.

Checks if analytics is enabled in the MobilePush SDK.

Kind: Static method of SFMCSdk

Returns: Future<bool> - A future to the boolean representation of whether analytics is enabled.

See Also

Enables or disables Predictive Intelligence analytics in the MobilePush SDK.

Kind: Static method of SFMCSdk

See Also

ParamTypeDescription
analyticsEnabledbooleanA flag indicating whether to enable Predictive Intelligence (PI) analytics.

Checks if Predictive Intelligence analytics is enabled in the MobilePush SDK.

Kind: Static method of SFMCSdk

Returns: Future<bool> - A future to the boolean representation of whether PI analytics is enabled.

See Also

To use the Flutter APIs, import the SFMCSdk package into your application as shown in the following example.

Where possible, we changed noninclusive terms to align with our company value of Equality. We retained noninclusive terms to document a third-party system, but we encourage the developer community to embrace more inclusive language. We can update the term when it’s no longer required for technical accuracy.