initialize method

Future<InitializationResult> initialize(
  1. String apiKey,
  2. CfConfiguration configuration,
  3. CfTarget target
)

Initializes the SDK client with provided API key, configuration and target. Returns information if initialization succeeded or not

Implementation

Future<InitializationResult> initialize(
    String apiKey, CfConfiguration configuration, CfTarget target) async {
  Logger.root.level = configuration.logLevel; // defaults to Level.INFO
  Logger.root.onRecord.listen((record) {
    print('${record.level.name}: ${record.time}: ${record.message}');
  });
  _hostChannel.setMethodCallHandler(_hostChannelHandler);
  bool initialized = false;
  try {
    initialized = await _channel.invokeMethod('initialize', {
      'apiKey': apiKey,
      'configuration': configuration._toCodecValue(),
      'target': target._toCodecValue()
    });
  } on PlatformException catch (e) {
    // For now just log the error. In the future, we should add retry and backoff logic.
    log.severe(e.message ??
        'Error message was empty' +
            (e.details ?? 'Error details was empty').toString());
    return new Future(() => InitializationResult(false));
  }
  return new Future(() => InitializationResult(initialized));
}