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
IamModule.setInAppMessageDecisionHandler(handler);
Parameters
| Parameter | Type | Description |
|---|---|---|
handler |
InAppMessageDecisionHandler? |
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
import 'package:sfmc_iam/sfmc_iam.dart';
await IamModule.requestSdk();
IamModule.setInAppMessageDecisionHandler((message) => message.id != 'blocked-id');
showInAppMessage
Displays a specific in-app message by its identifier.
Syntax
IamModule.showInAppMessage(id);
Parameters
| Parameter | Type | Description |
|---|---|---|
id |
String |
The identifier of the in-app message to display. If this value is blank or null, the API rejects the request. |
Returns
Future<void>
Example
import 'package:sfmc_iam/sfmc_iam.dart';
await IamModule.requestSdk();
await IamModule.showInAppMessage('welcome-message');
See Also
inAppMessageEvents
A broadcast stream of in-app message lifecycle events (shouldShow, didShow, didClose).
Syntax
IamModule.inAppMessageEvents;
Returns
Stream<InAppMessageEvent>- Emits anInAppMessageEventeach time an in-app message's lifecycle phase changes.
Example
import 'package:sfmc_iam/sfmc_iam.dart';
await IamModule.requestSdk();
IamModule.inAppMessageEvents.listen((event) {
switch (event.type) {
case InAppMessageEventType.shouldShow:
// About to display: consult custom rules if needed.
break;
case InAppMessageEventType.didShow:
// Message is now on screen: record impression.
break;
case InAppMessageEventType.didClose:
// Message dismissed: record close.
break;
}
debugPrint('IAM ${event.type.name}: ${event.message.id}');
});
setInAppMessageFont
Sets the font used to render in-app messages.
Syntax
IamModule.setInAppMessageFont(fontName);
Parameters
| Parameter | Type | Description |
|---|---|---|
fontName |
String? |
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
import 'package:sfmc_iam/sfmc_iam.dart';
await IamModule.requestSdk();
await 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
IamModule.setStatusBarColor(colorArgb);
Parameters
| Parameter | Type | Description |
|---|---|---|
colorArgb |
int |
A 32-bit ARGB color value, such as 0xFF0000FF. |
Returns
Future<void>
Example
import 'package:sfmc_iam/sfmc_iam.dart';
await IamModule.requestSdk();
await IamModule.setStatusBarColor(0xFF0000FF);