BloomEnv class
Environment configuration store, parser, and type-safe reader for Bloom JS Native applications.
BloomEnv manages runtime environment variables from multiple sources:
- Parsing
.envfiles via loadContent. - Dynamic configuration maps via loadMap.
- Compile-time
--dart-defineconstants via loadDartDefines.
Accessing Variables
- Strongly-typed schema validation via validate (recommended).
- Direct typed getters (get, getInt, getDouble, getBool) which throw StateError on missing keys without defaults.
- Safe nullable lookup via getOrNull.
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
Static Methods
-
clear(
) → void - Clears all loaded environment variables from the internal store.
-
contains(
String key) → bool -
Checks whether
keyexists 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 returnsnullifkeyis absent. -
has(
String key) → bool -
Checks whether
keyexists in the loaded environment map. -
isPublic(
String key) → bool -
Checks whether
keyis designated as client-public. -
loadContent(
String content, {bool overwrite = true}) → void -
Parses a raw
.envformatted content string and loads the resulting key-value pairs into the runtime map. -
loadDartDefines(
Map< String, String> defines, {bool overwrite = false}) → void -
Seeds
--dart-definecompile-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.