initialize static method

void initialize({
  1. KeyMode keyMode = KeyMode.dartDefine,
  2. String? apiKey,
})

Implementation

static void initialize({
  KeyMode keyMode = KeyMode.dartDefine,
  String? apiKey,
}) {
  assert(
    !_instance._initialized,
    'This instance is already initialized',
  );

  switch (keyMode) {
    case KeyMode.normal:
      if (apiKey == null || apiKey.isEmpty) {
        throw ArgumentError('You must provide an API key when using KeyMode.normal');
      }
      _instance._init(apiKey);
    case KeyMode.dartDefine:
      const apiKey = String.fromEnvironment(
        Constants.khipuAPIKey,
        defaultValue: Constants.empty
      );

      if (apiKey.isEmpty) {
        throw ArgumentError('You must provide an API key when using KeyMode.dartDefine');
      }

      _instance._init(apiKey);
  }
}