BloomEnvironmentSchema class abstract
Abstract base class for defining strictly typed and validated environment variable schemas.
Subclasses declare strongly-typed configuration properties using schema helper methods like requireString, optionalInt, requireBool, and requireUri. When validated via BloomEnv.validate, any missing required keys or malformed values are collected into validationErrors and thrown as a BloomEnvironmentException.
Backend Behavior
- SSR & VM: Evaluated during server bootstrap before serving requests.
- Browser: Evaluated during client startup after loading embedded configs or
--dart-defineconstants.
Example
class AppConfig extends BloomEnvironmentSchema {
late final String apiUrl = requireString('API_URL', description: 'Backend API base URL');
late final int port = optionalInt('PORT', defaultValue: 8080);
late final bool debugMode = optionalBool('DEBUG', defaultValue: false);
late final Uri authEndpoint = requireUri('AUTH_URL');
@override
void validate() {
// Trigger evaluation of late fields to collect any errors
apiUrl;
port;
debugMode;
authEndpoint;
}
}
void main() {
BloomEnv.loadContent('API_URL=https://api.example.com\nAUTH_URL=https://auth.example.com');
final config = BloomEnv.validate(AppConfig());
print('Port: ${config.port}');
}
See also:
- BloomEnv.validate, the validator function that evaluates a schema.
- BloomEnvironmentException, thrown when validation fails.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
validationErrors
→ List<
String> -
An unmodifiable list of accumulated validation errors encountered during schema evaluation.
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
optionalBool(
String key, {bool defaultValue = false, String? description}) → bool - Reads an optional boolean environment variable with default fallback.
-
optionalDouble(
String key, {double? defaultValue, String? description}) → double -
Reads an optional double environment variable, falling back to
defaultValueor0.0. -
optionalInt(
String key, {int? defaultValue, String? description}) → int -
Reads an optional integer environment variable, falling back to
defaultValueor0. -
optionalString(
String key, {String? defaultValue, String? description}) → String? -
Reads an optional string environment variable, falling back to
defaultValue. -
optionalUri(
String key, {Uri? defaultValue, String? description}) → Uri? -
Reads an optional URI environment variable, falling back to
defaultValue. -
requireBool(
String key, {String? description}) → bool - Reads a required boolean environment variable.
-
requireDouble(
String key, {String? description}) → double - Reads a required double-precision floating-point environment variable.
-
requireInt(
String key, {String? description}) → int - Reads a required integer environment variable.
-
requireString(
String key, {String? description}) → String - Reads a required non-empty string environment variable.
-
requireUri(
String key, {String? description}) → Uri - Reads a required absolute URI environment variable.
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
) → void - Evaluates and validates schema fields.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited