Initialization
To initialize the SDK you have to add MBMessages to the array of plugins of MBurger.
1
MBManager.shared.apiToken = 'YOUR_API_TOKEN';
2
MBManager.shared.plugins = [MBMessages()];
Copied!
To show in app message correctly you have to embed your main widget in a MBMessagesBuilder like this:
1
@override
2
Widget build(BuildContext context) {
3
return MaterialApp(
4
...
5
home: MBMessagesBuilder(
6
child: Scaffold(
7
...
8
),
9
),
10
);
11
}
Copied!
Why? To present in app messages MBMessages uses the showDialog function that needs a BuildContext. Embedding your main Scaffold in a MBMessagesBuilder let the SDK know always what context to use to show in app messages.

Initialize MBMessages with parameters

You can set a couples of parameters when initializing the MBMessages plugin:
1
MBMessages messagesPlugin = MBMessages(
2
messagesDelay: 1,
3
automaticallyCheckMessagesAtStartup: true,
4
debug: false,
5
themeForMessage: (message) => MBInAppMessageTheme(),
6
onButtonPressed: (button) => _buttonPressed(button),
7
);
Copied!
  • messagesDelay: it's the time after which the messages will be displayed once fetched
  • automaticallyCheckMessagesAtStartup: if the plugin should automatically check messages at startup. By default it's true.
  • debug: if this is set to true, all the message returned by the server will be displayed, if this is set to false a message will appear only once for app installation. This is false by default
  • themeForMessage: a function to provide a message theme (colors and fonts) for in app messages.
  • onButtonPressed: a callback called when a button of an in app message iis pressed.
Last modified 1yr ago