startSDK method
void
startSDK({
- RequestSuccessListener? onSuccess,
- RequestErrorListener? onError,
Initializes the SDK and sets up a method call handler to listen for native callbacks.
Guards against multiple initializations with _isSdkStarted
Implementation
void startSDK({
RequestSuccessListener? onSuccess,
RequestErrorListener? onError,
}) {
if (_isSdkStarted) {
return;
}
_isSdkStarted = true;
if (onSuccess != null || onError != null) {
_methodChannel.setMethodCallHandler((call) async {
switch (call.method) {
case 'onSuccess':
onSuccess?.call();
_methodChannel.setMethodCallHandler(null);
break;
case 'onError':
final int errorCode = call.arguments['errorCode'];
final String errorMessage = call.arguments['errorMessage'];
onError?.call(errorCode, errorMessage);
_methodChannel.setMethodCallHandler(null);
break;
default:
print('Unknown method called from the native side.');
_isSdkStarted = false;
_methodChannel.setMethodCallHandler(null);
break;
}
});
_methodChannel.invokeMethod('startSDKwithHandler');
} else {
_methodChannel.invokeMethod('startSDK');
}
}