In-App Messaging

This section provides API reference details for the In-App Messaging module in the Flutter unified plugin.

setInAppMessageDecisionHandler 

Registers a handler that decides whether the SDK should display an in-app message. This handler gives the app the final say over the native shouldShowMessage or shouldShow delegate.

Syntax 

1IamModule.setInAppMessageDecisionHandler(handler);

Parameters 

ParameterTypeDescription
handlerInAppMessageDecisionHandler?Invoked with the full InAppMessage to decide whether it should display. Return or complete with true to display the message, false to suppress it. Pass null to clear the handler and restore default SDK behavior, where every message shows immediately.

Returns 

  • Future<void>

Example 

1import 'package:sfmc_iam/sfmc_iam.dart';
2
3await IamModule.requestSdk();
4IamModule.setInAppMessageDecisionHandler((message) => message.id != 'blocked-id');

showInAppMessage 

Displays a specific in-app message by its identifier.

Syntax 

1IamModule.showInAppMessage(id);

Parameters 

ParameterTypeDescription
idStringThe identifier of the in-app message to display. If this value is blank or null, the API rejects the request.

Returns 

  • Future<void>

Example 

1import 'package:sfmc_iam/sfmc_iam.dart';
2
3await IamModule.requestSdk();
4await IamModule.showInAppMessage('welcome-message');

See Also 

inAppMessageEvents 

A broadcast stream of in-app message lifecycle events (shouldShow, didShow, didClose).

Syntax 

1IamModule.inAppMessageEvents;

Returns 

  • Stream<InAppMessageEvent> - Emits an InAppMessageEvent each time an in-app message’s lifecycle phase changes.

Example 

1import 'package:sfmc_iam/sfmc_iam.dart';
2
3await IamModule.requestSdk();
4IamModule.inAppMessageEvents.listen((event) {
5  switch (event.type) {
6    case InAppMessageEventType.shouldShow:
7      // About to display: consult custom rules if needed.
8      break;
9    case InAppMessageEventType.didShow:
10      // Message is now on screen: record impression.
11      break;
12    case InAppMessageEventType.didClose:
13      // Message dismissed: record close.
14      break;
15  }
16  debugPrint('IAM ${event.type.name}: ${event.message.id}');
17});

setInAppMessageFont 

Sets the font used to render in-app messages.

Syntax 

1IamModule.setInAppMessageFont(fontName);

Parameters 

ParameterTypeDescription
fontNameString?The font name to apply. In Android, the name is resolved with Typeface.create. In iOS, it’s the PostScript name passed to setInAppMessageFont. Pass null to revert to the system default font.

Returns 

  • Future<void>

Example 

1import 'package:sfmc_iam/sfmc_iam.dart';
2
3await IamModule.requestSdk();
4await IamModule.setInAppMessageFont('HelveticaNeue-Bold');

See Also 

setStatusBarColor 

Sets the status bar color of the in-app message activity. Only Android apps support this capability.

Syntax 

1IamModule.setStatusBarColor(colorArgb);

Parameters 

ParameterTypeDescription
colorArgbintA 32-bit ARGB color value, such as 0xFF0000FF.

Returns 

  • Future<void>

Example 

1import 'package:sfmc_iam/sfmc_iam.dart';
2
3await IamModule.requestSdk();
4await IamModule.setStatusBarColor(0xFF0000FF);

See Also