mindbox 2.1.0 mindbox: ^2.1.0 copied to clipboard
Flutter Mindbox SDK. Plugin wrapper over of Mindbox iOS/Android SDK.
This plugin is a wrapper over the native Mindbox(iOS, Android) libraries that allows to receive and handle push notifications.
Features #
- Receive and show push notification in both mobile platforms.
- Receive push notification data(link, payload) in Flutter.
- Execute sync/async operations.
Getting started #
This plugin depends on the configuration of push notifications on native platforms. It's necessary to follow the steps specified in the guide:
Usage #
Initialization #
import 'package:mindbox/mindbox.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
final config = Configuration(
domain: "your domain",
endpointIos: "iOs endpoint",
endpointAndroid: "Android endpoint",
subscribeCustomerIfCreated: true,
);
Mindbox.instance.init(configuration: config);
runApp(MyApp());
}
Handling push click #
Mindbox.instance.onPushClickReceived((link, payload) {
print(payload);
switch (link) {
case 'mindbox.cloud':
Navigator.push(context, MaterialPageRoute(builder: (context) => ContentPage()));
break;
case 'mindbox.cloud/user':
Navigator.push(context, MaterialPageRoute(builder: (context) => ProfilePage()));
break;
default:
Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
}
});
Getting device UUID #
Mindbox.instance.getDeviceUUID((uuid) => print(uuid));
Getting APNS/FMS/HMS token #
Mindbox.instance.getToken((token) => print(token));
Execute async operation #
Mindbox.instance.executeAsyncOperation(
operationSystemName: 'operationName',
operationBody: {'example': 'body'},
);
Execute sync operation #
Mindbox.instance.executeSyncOperation(
operationSystemName: 'operationName',
operationBody: {'example': 'body'},
onSuccess: (String response) {
jsonDecode(response);
},
onError: (MindboxError error){
if (error is MindboxProtocolError) {
print(error.code);
}
print(error.message);
jsonDecode(error.data);
},
);