BloomEnv class

Environment configuration parser, store, and type-safe reader.

BloomEnv provides a centralized, in-memory environment configuration store:

  • Parsing: Load configuration from raw .env files via loadContent or from Dart maps via loadMap.
  • Compile-Time Defines: Seed --dart-define constants using loadDartDefines.
  • Type-Safe Accessors: Retrieve values typed as String, int, double, or bool with optional defaults or strict exception throwing on missing values.
  • Schema Validation: Validate strongly-typed configurations with validate and BloomEnvironmentSchema.

Example

// 1. Load from .env text
BloomEnv.loadContent('''
  APP_PORT=8080
  DEBUG=true
  DB_HOST=127.0.0.1
''');

// 2. Read typed values
final port = BloomEnv.getInt('APP_PORT', defaultValue: 3000);
final isDebug = BloomEnv.getBool('DEBUG');
final dbHost = BloomEnv.get('DB_HOST');

Constructors

BloomEnv()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

all Map<String, String>
A read-only snapshot map of all currently loaded environment variables.
no setter

Static Methods

clear() → void
Clears all loaded environment variables from the internal in-memory store.
contains(String key) bool
Checks whether an environment variable exists in the runtime store for key.
get(String key, {String? defaultValue}) String
Retrieves the string value for key.
getBool(String key, {bool? defaultValue}) bool
Retrieves the boolean value for key.
getDouble(String key, {double? defaultValue}) double
Retrieves the double value for key.
getInt(String key, {int? defaultValue}) int
Retrieves the integer value for key.
getOrNull(String key) String?
Retrieves the string value for key, or returns null if not found.
has(String key) bool
Checks whether an environment variable exists in the runtime store for key.
loadContent(String content, {bool overwrite = true}) → void
Parses and loads environment variables from a raw .env formatted content string.
loadDartDefines(Map<String, String> defines, {bool overwrite = false}) → void
Seeds --dart-define values into the runtime environment map.
loadMap(Map<String, String> map, {bool overwrite = true}) → void
Populates environment variables directly from a map of key-value pairs.
validate<T extends BloomEnvironmentSchema>(T schema) → T
Validates a typed BloomEnvironmentSchema instance against the currently loaded environment variables.