BloomEnvironmentSchema class abstract
Abstract base class for strictly typed and validated environment variable schemas.
Subclass BloomEnvironmentSchema to define your application's required and optional configuration variables with type parsing and descriptions.
Example
class AppConfig extends BloomEnvironmentSchema {
late final String appEnv = optionalString('APP_ENV', defaultValue: 'development')!;
late final int port = optionalInt('PORT', defaultValue: 8080);
late final String databaseUrl = requireString('DATABASE_URL', description: 'Postgres connection string');
late final bool debug = optionalBool('DEBUG', defaultValue: false);
late final Uri apiBase = requireUri('API_BASE_URL', description: 'Upstream API endpoint');
@override
void validate() {
// Force evaluation of late fields to trigger validation
appEnv;
port;
databaseUrl;
debug;
apiBase;
}
}
void main() {
BloomEnv.loadContent('DATABASE_URL=postgres://localhost:5432/db\nAPI_BASE_URL=https://api.example.com');
final config = BloomEnv.validate(AppConfig());
print('Connected to: ${config.databaseUrl} on port ${config.port}');
}
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> -
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 identified by
key. -
optionalDouble(
String key, {double? defaultValue, String? description}) → double -
Reads an optional double environment variable identified by
key. -
optionalInt(
String key, {int? defaultValue, String? description}) → int -
Reads an optional integer environment variable identified by
key. -
optionalString(
String key, {String? defaultValue, String? description}) → String? -
Reads an optional string environment variable identified by
key. -
optionalUri(
String key, {Uri? defaultValue, String? description}) → Uri? -
Reads an optional URI environment variable identified by
key. -
requireBool(
String key, {String? description}) → bool -
Requires a valid boolean environment variable identified by
key. -
requireDouble(
String key, {String? description}) → double -
Requires a valid double environment variable identified by
key. -
requireInt(
String key, {String? description}) → int -
Requires a valid integer environment variable identified by
key. -
requireString(
String key, {String? description}) → String -
Requires a non-empty string environment variable identified by
key. -
requireUri(
String key, {String? description}) → Uri -
Requires a valid absolute URI environment variable identified by
key. -
toString(
) → String -
A string representation of this object.
inherited
-
validate(
) → void -
Evaluates and validates schema fields. Subclasses can override to evaluate
latefields.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited