BloomEnv class

Environment configuration store, parser, and type-safe reader for Bloom JS Native applications.

BloomEnv manages runtime environment variables from multiple sources:

Accessing Variables

SSR & Browser Compatibility

Pure Dart with zero Flutter or DOM dependencies. Works identically during server-side rendering (SSR), Dart VM execution, and client-side web browser execution.

Example

// 1. Load configuration from a .env file content
BloomEnv.loadContent('''
API_BASE_URL=https://api.bloom.dev
PORT=8080
DEBUG=true
''');

// 2. Read values directly
final apiUrl = BloomEnv.get('API_BASE_URL');
final port = BloomEnv.getInt('PORT', defaultValue: 3000);
final isDebug = BloomEnv.getBool('DEBUG', defaultValue: false);

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>
Returns an unmodifiable snapshot map of all currently loaded environment variables.
no setter
publicVariables Map<String, String>
Returns an unmodifiable snapshot map of only the client-public environment variables.
no setter

Static Methods

clear() → void
Clears all loaded environment variables from the internal store.
contains(String key) bool
Checks whether key exists in the loaded environment map.
get(String key, {String? defaultValue}) String
Retrieves the string value for key.
getBool(String key, {bool? defaultValue}) bool
Retrieves and parses a boolean environment variable for key.
getDouble(String key, {double? defaultValue}) double
Retrieves and parses a double-precision floating-point environment variable for key.
getInt(String key, {int? defaultValue}) int
Retrieves and parses an integer environment variable for key.
getOrNull(String key) String?
Retrieves the string value for key, or returns null if key is absent.
has(String key) bool
Checks whether key exists in the loaded environment map.
isPublic(String key) bool
Checks whether key is designated as client-public.
loadContent(String content, {bool overwrite = true}) → void
Parses a raw .env formatted content string and loads the resulting key-value pairs into the runtime map.
loadDartDefines(Map<String, String> defines, {bool overwrite = false}) → void
Seeds --dart-define compile-time constants into the runtime environment map.
loadMap(Map<String, String> map, {bool overwrite = true}) → void
Populates environment variables directly from a key-value map.
validate<T extends BloomEnvironmentSchema>(T schema) → T
Validates a typed BloomEnvironmentSchema against current environment variables.

Constants

publicPrefix → const String
The prefix designating environment variables that are safe for client-side web exposure.