init method
Initializes the SDK for further work.
You can call this method multiple times to set new configuration params. Read more about Configuration parameter.
Implementation
Future<void> init({required Configuration configuration}) async {
try {
//ignore: unnecessary_null_comparison
if (ServicesBinding.instance == null) {
throw MindboxInitializeError(
message: 'Initialization error',
data: 'Try to invoke \'WidgetsFlutterBinding.ensureInitialized()\' '
'before initialization.');
}
await channel.invokeMethod('init', configuration.toMap());
if (!_methodHandlerSet) {
_setMethodCallHandler();
}
for (final callbackMethod in _pendingCallbackMethods) {
callbackMethod.callback(
await channel.invokeMethod(callbackMethod.methodName) ?? 'null');
}
for (final operation in _pendingOperations) {
channel.invokeMethod(operation.methodName, operation.parameters).then(
(result) {
if (operation.successCallback != null) {
operation.successCallback!(result);
}
}, onError: (e) {
if (operation.errorCallback != null) {
final mindboxError = _convertPlatformExceptionToMindboxError(e);
operation.errorCallback!(mindboxError);
}
});
}
_pendingCallbackMethods.clear();
_pendingOperations.clear();
_initialized = true;
} on PlatformException catch (e) {
throw MindboxInitializeError(
message: e.message ?? '', data: e.details ?? '');
}
}