get static method

String get(
  1. String key, {
  2. String? defaultValue,
})

Retrieves the string value for key.

If key exists in the environment map, returns its value. If missing and defaultValue is provided, returns defaultValue. If missing and no defaultValue is provided, throws a StateError.

final host = BloomEnv.get('HOST', defaultValue: 'localhost');

Implementation

static String get(String key, {String? defaultValue}) {
  if (_env.containsKey(key)) {
    return _env[key]!;
  }
  if (defaultValue != null) {
    return defaultValue;
  }
  throw StateError(
      'BloomEnv: Missing required environment variable "$key".');
}