Marketing Cloud Engagement SDK

This section provides API reference details for the Marketing Cloud Engagement SDK module in the Flutter unified plugin.

refreshInbox

Requests an updated list of inbox messages from the Marketing Cloud servers.

Syntax

MarketingCloudSdk.refreshInbox();

Returns

  • Future<bool> - Indicates whether the refresh request succeeded.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final refreshed = await MarketingCloudSdk.refreshInbox();

See Also

getAllMessages

Retrieves all active inbox messages, including read and unread messages. Doesn't retrieve deleted inbox messages.

Syntax

MarketingCloudSdk.getAllMessages();

Returns

  • Future<List<InboxMessage>> - A future that completes with the list of inbox messages.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final messages = await MarketingCloudSdk.getAllMessages();

See Also

getUnreadMessages

Retrieves all active, unread inbox messages. Doesn't retrieve deleted inbox messages.

Syntax

MarketingCloudSdk.getUnreadMessages();

Returns

  • Future<List<InboxMessage>> - A future that completes with the list of unread inbox messages.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final messages = await MarketingCloudSdk.getUnreadMessages();

See Also

getReadMessages

Retrieves all active, read inbox messages. Doesn't retrieve unread inbox messages.

Syntax

MarketingCloudSdk.getReadMessages();

Returns

  • Future<List<InboxMessage>> - A future that completes with the list of read inbox messages.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final messages = await MarketingCloudSdk.getReadMessages();

See Also

getDeletedMessages

Retrieves all active, deleted inbox messages.

Syntax

MarketingCloudSdk.getDeletedMessages();

Returns

  • Future<List<InboxMessage>> - A future that completes with the list of deleted inbox messages.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final messages = await MarketingCloudSdk.getDeletedMessages();

See Also

getMessageCount

Retrieves the total number of inbox messages, excluding deleted messages.

Syntax

MarketingCloudSdk.getMessageCount();

Returns

  • Future<int?> - A future that completes with the total inbox message count.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final count = await MarketingCloudSdk.getMessageCount();

See Also

getUnreadMessageCount

Retrieves the total number of unread inbox messages, excluding deleted messages.

Syntax

MarketingCloudSdk.getUnreadMessageCount();

Returns

  • Future<int?> - A future that completes with the unread inbox message count.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final count = await MarketingCloudSdk.getUnreadMessageCount();

See Also

getReadMessageCount

Retrieves the total number of read inbox messages, excluding deleted messages.

Syntax

MarketingCloudSdk.getReadMessageCount();

Returns

  • Future<int?> - A future that completes with the read inbox message count.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final count = await MarketingCloudSdk.getReadMessageCount();

See Also

getDeletedMessageCount

Retrieves the total number of deleted inbox messages.

Syntax

MarketingCloudSdk.getDeletedMessageCount();

Returns

  • Future<int?> - A future that completes with the deleted inbox message count.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final count = await MarketingCloudSdk.getDeletedMessageCount();

See Also

markMessageRead

Marks an inbox message as read in local storage.

Syntax

MarketingCloudSdk.markMessageRead(id);

Parameters

Parameter Type Description
id String The ID of the inbox message to mark as read.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.markMessageRead('message-id-123');

See Also

markMessageDeleted

Marks an inbox message as deleted in local storage.

Syntax

MarketingCloudSdk.markMessageDeleted(id);

Parameters

Parameter Type Description
id String The ID of the inbox message to mark as deleted.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.markMessageDeleted('message-id-123');

See Also

markAllMessagesRead

Marks all active, unread inbox messages as read.

Syntax

MarketingCloudSdk.markAllMessagesRead();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.markAllMessagesRead();

See Also

markAllMessagesDeleted

Marks all active inbox messages as deleted.

Syntax

MarketingCloudSdk.markAllMessagesDeleted();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.markAllMessagesDeleted();

See Also

trackInboxMessageOpened

Tracks the opening of an inbox message for analytics.

Syntax

MarketingCloudSdk.trackInboxMessageOpened(id);

Parameters

Parameter Type Description
id String The ID of the inbox message that was opened.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.trackInboxMessageOpened('message-id-123');

See Also

addTag

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

Syntax

MarketingCloudSdk.addTag(tag);

Parameters

Parameter Type Description
tag String The tag to add.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.addTag('vip-customer');

See Also

addTags

Adds multiple tags to the list of tags in the registration.

Syntax

MarketingCloudSdk.addTags(tags);

Parameters

Parameter Type Description
tags List<String> The list of tags to add.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.addTags(['vip-customer', 'newsletter-subscriber']);

See Also

removeTag

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

Syntax

MarketingCloudSdk.removeTag(tag);

Parameters

Parameter Type Description
tag String The tag to remove.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.removeTag('vip-customer');

See Also

removeTags

Removes multiple tags from the list of tags in the registration.

Syntax

MarketingCloudSdk.removeTags(tags);

Parameters

Parameter Type Description
tags List<String> The list of tags to remove.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.removeTags(['vip-customer', 'newsletter-subscriber']);

See Also

getTags

Returns the tags currently set on the device.

Syntax

MarketingCloudSdk.getTags();

Returns

  • Future<List<String>?> - A future that completes with the list of tags currently set on the device.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final tags = await MarketingCloudSdk.getTags();

See Also

getAttributes

Returns a map of attributes set in the registration.

This method is deprecated. Use SFMCSdkModule.getAttributes from sfmc_core instead. SFMCSdkModule.getAttributes coerces null attribute values to an empty string ('') rather than the literal string "null".

Syntax

MarketingCloudSdk.getAttributes();

Returns

  • Future<Map<String, String>?> - A future that completes with the map of attributes set in the registration.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final attributes = await MarketingCloudSdk.getAttributes();

getDeviceId

Returns the device ID that Marketing Cloud uses to send push messages to the device.

Syntax

MarketingCloudSdk.getDeviceId();

Returns

  • Future<String?> - A future that completes with the device ID.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final deviceId = await MarketingCloudSdk.getDeviceId();

See Also

getContactKey

Returns the contact key for the device.

This method is deprecated. Use SFMCSdkModule.getProfileId from sfmc_core instead.

Syntax

MarketingCloudSdk.getContactKey();

Returns

  • Future<String?> - A future that completes with the contact key currently set on the device.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final contactKey = await MarketingCloudSdk.getContactKey();

setSignedString

Sets the signed string for device/contact authentication. The signed string is typically a JWT used to authenticate the device or contact, and this feature must be enabled on the Marketing Cloud account.

Syntax

MarketingCloudSdk.setSignedString(signedString);

Parameters

Parameter Type Description
signedString String? The signed string to set. Pass null to clear the value.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.setSignedString('eyJhbGciOiJIUzI1NiJ9...');

See Also

getSignedString

Returns the signed string for the device. The signed string is usually a JWT used to authenticate the device or contact. If no signed string is set, this method returns null.

Syntax

MarketingCloudSdk.getSignedString();

Returns

  • Future<String?> - A future that completes with the signed string, or null if no signed string is set.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final signedString = await MarketingCloudSdk.getSignedString();

See Also

enablePiAnalytics

Enables Predictive Intelligence analytics in the Marketing Cloud SDK.

Syntax

MarketingCloudSdk.enablePiAnalytics();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.enablePiAnalytics();

See Also

disablePiAnalytics

Disables Predictive Intelligence analytics in the Marketing Cloud SDK.

Syntax

MarketingCloudSdk.disablePiAnalytics();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.disablePiAnalytics();

See Also

isPiAnalyticsEnabled

Checks if Predictive Intelligence analytics is enabled.

Syntax

MarketingCloudSdk.isPiAnalyticsEnabled();

Returns

  • Future<bool> - Indicates whether Predictive Intelligence analytics is enabled.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final enabled = await MarketingCloudSdk.isPiAnalyticsEnabled();

See Also

enableAnalytics

Enables analytics in the Marketing Cloud SDK.

Syntax

MarketingCloudSdk.enableAnalytics();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.enableAnalytics();

See Also

disableAnalytics

Disables analytics in the Marketing Cloud SDK.

Syntax

MarketingCloudSdk.disableAnalytics();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.disableAnalytics();

See Also

isAnalyticsEnabled

Checks if analytics is enabled in the Marketing Cloud SDK.

Syntax

MarketingCloudSdk.isAnalyticsEnabled();

Returns

  • Future<bool> - Indicates whether analytics is enabled.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final enabled = await MarketingCloudSdk.isAnalyticsEnabled();

See Also

enableLogging

Enables verbose logging within the native Marketing Cloud SDK.

Syntax

MarketingCloudSdk.enableLogging();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.enableLogging();

See Also

disableLogging

Disables verbose logging within the native Marketing Cloud SDK.

Syntax

MarketingCloudSdk.disableLogging();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.disableLogging();

See Also

setRegistrationCallback

Registers a callback to receive registration change events from the SDK.

Syntax

MarketingCloudSdk.setRegistrationCallback();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.setRegistrationCallback();

See Also

unsetRegistrationCallback

Unregisters the registration change callback.

Syntax

MarketingCloudSdk.unsetRegistrationCallback();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.unsetRegistrationCallback();

See Also

registrationEvents

A broadcast stream of registration events. Emits a map that contains registration data when the registration changes.

Syntax

MarketingCloudSdk.registrationEvents;

Returns

  • Stream<Map<String, dynamic>> - A broadcast stream that emits a map of registration data when the registration changes.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
MarketingCloudSdk.registrationEvents.listen((event) {
  print('Registration changed: $event');
});

registerInboxResponseListener

Registers a listener for inbox message changes.

Syntax

MarketingCloudSdk.registerInboxResponseListener(listener);

Parameters

Parameter Type Description
listener InboxResponseListener The callback invoked when an inbox message changes.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();

void onInboxChanged(List<InboxMessage> messages) {
  print('Inbox changed: ${messages.length} messages');
}

await MarketingCloudSdk.registerInboxResponseListener(onInboxChanged);

unregisterInboxResponseListener

Unregisters a previously registered inbox response listener.

Syntax

MarketingCloudSdk.unregisterInboxResponseListener(listener);

Parameters

Parameter Type Description
listener InboxResponseListener The callback to remove.

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();

void onInboxChanged(List<InboxMessage> messages) {
  print('Inbox changed: ${messages.length} messages');
}

await MarketingCloudSdk.registerInboxResponseListener(onInboxChanged);
await MarketingCloudSdk.unregisterInboxResponseListener(onInboxChanged);

enableLocation

Enables the location (geofence) feature at runtime. In iOS apps, flips the developer override on MarketingCloudSdk. In Android apps, enables geofence messaging using RegionMessageManager. Request the required OS location permissions before you call this method.

Syntax

MarketingCloudSdk.enableLocation();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.enableLocation();
final enabled = await MarketingCloudSdk.isLocationEnabled();

See Also

disableLocation

Disables the location (geofence) feature at runtime. In iOS apps, flips the developer override on MarketingCloudSdk. In Android apps, disables geofence messaging using RegionMessageManager.

Syntax

MarketingCloudSdk.disableLocation();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.disableLocation();

See Also

isLocationEnabled

Reports whether the location, or the geofence feature, is enabled.

Syntax

MarketingCloudSdk.isLocationEnabled();

Returns

  • Future<bool> - Indicates whether the location (geofence) feature is enabled.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final enabled = await MarketingCloudSdk.isLocationEnabled();

See Also

startWatchingLocation

In iOS apps, starts tracking the coordinates of an app user. In Android apps, geofence transitions are driven by enableLocation and disableLocation.

Syntax

MarketingCloudSdk.startWatchingLocation();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.startWatchingLocation();

See Also

stopWatchingLocation

In iOS apps, stops tracking the app user's location.

Syntax

MarketingCloudSdk.stopWatchingLocation();

Returns

  • Future<void>

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
await MarketingCloudSdk.stopWatchingLocation();

See Also

isWatchingLocation

In iOS apps, reports whether the SDK actively watches the app user's location. In Android apps, always returns false.

Syntax

MarketingCloudSdk.isWatchingLocation();

Returns

  • Future<bool> - Indicates whether the SDK is actively watching the app user's location.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final watching = await MarketingCloudSdk.isWatchingLocation();

See Also

getLastKnownLocation

Returns the last known device location as reported by the native SDK. iOS returns a raw [String: String] dictionary, which usually includes latitude and longitude keys. Returns null when the app hasn't captured any data. Always returns null in Android apps.

Syntax

MarketingCloudSdk.getLastKnownLocation();

Returns

  • Future<Map<String, String>?> - A future that completes with the last known location, or null if unavailable.

Example

import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';

await MarketingCloudSdk.requestSdk();
final location = await MarketingCloudSdk.getLastKnownLocation();
if (location != null) {
  final lat = location['latitude'];
  final lng = location['longitude'];
  debugPrint('Last known: $lat, $lng');
}

See Also

enableProximityMessaging

In Android apps, enables proximity (beacon) messaging and requires ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION.

Syntax

MarketingCloudSdk.enableProximityMessaging();

Returns

  • Future<void>