applyEnvironment static method

void applyEnvironment(
  1. dynamic environment
)

Apply predefined environment configuration

Type-safe way to configure Zenify for different environments.

Example:

// Type-safe (recommended)
ZenConfig.applyEnvironment(ZenEnvironment.production);

Passing a String is deprecated and will be removed in v3.0.0. Use ZenEnvironment enum values instead.

Implementation

static void applyEnvironment(dynamic environment) {
  final ZenEnvironment env;

  if (environment is ZenEnvironment) {
    env = environment;
  } else if (environment is String) {
    ZenLogger.logWarning(
      'Passing String "$environment" to ZenConfig.applyEnvironment() is '
      'deprecated and will be removed in v3.0.0. '
      'Use ZenEnvironment.$environment instead.',
    );
    env = ZenEnvironment.fromString(environment);
  } else {
    throw ArgumentError(
        'Environment must be ZenEnvironment or String, got ${environment.runtimeType}');
  }

  switch (env) {
    case ZenEnvironment.production:
      _applyProductionConfig();
      break;

    case ZenEnvironment.productionVerbose:
      _applyProductionVerboseConfig();
      break;

    case ZenEnvironment.staging:
      _applyStagingConfig();
      break;

    case ZenEnvironment.development:
      _applyDevelopmentConfig();
      break;

    case ZenEnvironment.debug:
      _applyDebugConfig();
      break;

    case ZenEnvironment.trace:
      _applyTraceConfig();
      break;

    case ZenEnvironment.test:
      _applyTestConfig();
      break;
  }
}