initialize static method

Future<void> initialize({
  1. Map<String, dynamic> configMap = const {},
})

Initializes the configuration by loading the config file and sending it to the native layer.

Implementation

static Future<void> initialize(
    {Map<String, dynamic> configMap = const {}}) async {
  try {
    if (Platform.isAndroid) {
      if (configMap.isNotEmpty) {
        //Write code here when sending config map from main.dart
        await MethodHandler.invokeNativeMethod('initialize',
            arguments: {'configMap': configMap});
      } else {
        // Load the configuration file from assets.
        final configString =
            await loadConfigAsset(); // Invoke the native method to initialize the config with the loaded data.
        await MethodHandler.invokeNativeMethod('initialize',
            arguments: {'config': configString});
      }
    } else {
      // Passing the configMap to the Osmos SDK native code if it is provided
      await MethodHandler.invokeNativeMethod('initialize',
          arguments: {'config': (configMap.isNotEmpty) ? configMap : {}});
    }
  } on OsmosException {
    rethrow;
  } catch (e) {
    throw OsmosException(
      errorCode: OsmosErrorCodes.initializationError,
      details: 'Failed to initialize Osmos SDK: ${e.toString()}',
      nativeError: e,
    );
  }
}