Env class
Reads configuration from the process environment.
Environment variables are read at runtime, unlike --dart-define
values, which are compile-time constants baked into the binary. That is the
difference that matters in a container: the same image is promoted from
staging to production and told what it is by its environment, so anything
that differs between deployments — a port, a peer's address, a database
URL — has to be read here rather than defined at build time.
final users = Env.current.uri('USERS_SERVICE_URL');
final key = Env.current.require('API_KEY');
Takes an explicit map in tests, so a suite never has to mutate the real process environment:
final env = Env({'PORT': '9000'});
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
-
boolean(
String name, {required bool orElse}) → bool - The value parsed as a boolean.
-
has(
String name) → bool -
integer(
String name, {required int orElse}) → int - The value parsed as an integer.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
require(
String name) → String - The value, throwing when unset.
-
string(
String name, {required String orElse}) → String -
The value, or
orElsewhen unset. -
toString(
) → String -
A string representation of this object.
inherited
-
uri(
String name, {Uri? orElse}) → Uri - The value parsed as a URI — a peer service's base address, typically.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
String name) → String? - The raw value, or null when unset.