init static method

Initializes the VWO FME Flutter SDK.

This method is the entry point for setting up and configuring the VWO FME Flutter SDK. It establishes communication with the native SDKs (Android/iOS) and prepares the SDK for use.

This method should be called once during the application's startup.

options The initialization options for the VWO FME SDK. This object contains configuration details such as the account ID, environment key, and other settings.

Returns a Future that completes with an instance of MethodChannelVwoFmeFlutterSdk if the initialization is successful, or error if the initialization fails.

Implementation

static Future<MethodChannelVwoFmeFlutterSdk?> init(
    VWOInitOptions options) async {

  // Validate required parameters
  if (options.sdkKey.isEmpty) {
    return Future.error(
        ArgumentError('sdkKey is required and cannot be empty'));
  }
  if (options.accountId <= 0) {
    return Future.error(ArgumentError(
        'accountId is required and must be a positive integer'));
  }
  List<Map<String, dynamic>> transportsCopy =
      _prepareLoggersForBridge(options);

    final parameters = {
      'sdkKey': options.sdkKey,
      'accountId': options.accountId,
      'logger': options.logger,
      'gatewayService': options.gatewayService,
      'pollInterval': options.pollInterval,
      'cachedSettingsExpiryTime': options.cachedSettingsExpiryTime,
      'batchMinSize': options.batchMinSize,
      'batchUploadTimeInterval': "${options.batchUploadTimeInterval}",
    };

  var flutterSdk = MethodChannelVwoFmeFlutterSdk();
  // Set the integration callback handler if provided
  flutterSdk._setBridgeCallbackHandler(options);
  flutterSdk._transports = transportsCopy;

  await methodChannel.invokeMethod('init', parameters);
  return flutterSdk;
}