PlayxEnv class abstract
Application configuration from .env files, flavors and --dart-define.
Call load once at startup (done by PlayxCore.bootCore when
envSettings is provided), then read values synchronously:
final apiUrl = PlayxEnv.getUri('API_URL', fallback: Uri.parse('https://api.example.com'));
final retries = PlayxEnv.getInt('RETRIES', fallback: 3);
The getters are shortcuts for the same getters on values. See PlayxEnvSettings for how files and values are layered.
Security: .env files ship as plain text inside the app. Never put
secrets in them.
Constructors
- PlayxEnv()
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> -
Every loaded value except secure ones, safe to log or display.
no setter
- environment → String?
-
The environment resolved by load (e.g.
prod), if any.no setter - isLoaded → bool
-
Whether load, loadFromString or setMockValues has been called.
no setter
-
loadedFiles
→ List<
String> -
The files that were found and loaded, in order.
no setter
- values → EnvValues
-
The loaded values. Empty, with a logged warning, before load.
no setter
Static Methods
-
containsKey(
String key) → bool -
Whether
keyhas a value. -
dispose(
) → Future< void> - Clears all values. load must be called again before use.
-
getBool(
String key, {bool fallback = false}) → bool -
Returns the value of
keyas abool, orfallback. -
getDouble(
String key, {double fallback = -1}) → double -
Returns the value of
keyas adouble, orfallback. -
getDuration(
String key, {required Duration fallback}) → Duration -
Returns the value of
keyas a Duration, orfallback. -
getEnum<
T extends Enum> (String key, List< T> enumValues, {required T fallback}) → T -
Returns the enum value of values matching the value of
key, orfallback. -
getInt(
String key, {int fallback = -1}) → int -
Returns the value of
keyas anint, orfallback. -
getList<
T> (String key, {List< T> fallback = const [], T fromJson(dynamic json)?, String separator = ','}) → List<T> -
Returns the value of
keyas a list, orfallback. -
getMap(
String key, {Map< String, dynamic> fallback = const {}}) → Map<String, dynamic> -
Returns the value of
keyparsed as a JSON object, orfallback. -
getNum(
String key, {num fallback = -1}) → num -
Returns the value of
keyas anum, orfallback. -
getObject<
T> (String key, {required T fromJson(dynamic json), required T fallback}) → T -
Returns the value of
keyconverted withfromJson, orfallback. -
getString(
String key, {String fallback = ''}) → String -
Returns the value of
key, orfallbackif it isn't set. -
getUri(
String key, {required Uri fallback}) → Uri -
Returns the value of
keyas a Uri, orfallback. -
isSecure(
String key) → bool -
Whether
keyholds a secure value (see PlayxEnvSettings.secureEnv). -
load(
[PlayxEnvSettings settings = const PlayxEnvSettings()]) → Future< void> -
Loads the configuration described by
settings. -
loadFromString(
String content, {Map< String, String> mergeWith = const {}, Map<String, String> dartDefines = const {}, List<String> requiredKeys = const [], bool usePlayxDefines = true, Parser parser = const Parser()}) → void -
Loads values from
contentin.envformat, thenmergeWith,PLAYX_DEFINES(ifusePlayxDefines) anddartDefines. Useful in tests, or for config fetched at runtime. -
maybeGetBool(
String key) → bool? -
Returns the value of
keyas abool:true/1orfalse/0(case-insensitive).nullif it isn't set or is anything else. -
maybeGetDouble(
String key) → double? -
Returns the value of
keyas adouble, ornullif it isn't set or isn't a number. -
maybeGetDuration(
String key) → Duration? -
Returns the value of
keyas a Duration, ornullif it isn't set or can't be parsed. -
maybeGetEnum<
T extends Enum> (String key, List< T> enumValues) → T? -
Returns the enum value of values whose name matches the value of
key(case-insensitive), ornull. -
maybeGetInt(
String key) → int? -
Returns the value of
keyas anint, ornullif it isn't set or isn't a number. Decimals are truncated. -
maybeGetList<
T> (String key, {T fromJson(dynamic json)?, String separator = ','}) → List< T> ? -
Returns the value of
keyas a list, ornullif it isn't set or an item can't be converted. -
maybeGetMap(
String key) → Map< String, dynamic> ? -
Returns the value of
keyparsed as a JSON object, ornull. -
maybeGetNum(
String key) → num? -
Returns the value of
keyas anum, ornullif it isn't set or isn't a number. -
maybeGetObject<
T> (String key, {required T fromJson(dynamic json)}) → T? -
Returns the value of
keyparsed as JSON and converted withfromJson, ornullif it isn't set, isn't valid JSON, orfromJsonthrows. -
maybeGetString(
String key) → String? -
Returns the value of
key, ornullif it isn't set. -
maybeGetUri(
String key) → Uri? -
Returns the value of
keyas a Uri, ornullif it isn't set or can't be parsed. -
setMockValues(
Map< String, String> values) → void -
Replaces all values with
values, for tests.