EnvValues class

A read-only set of configuration values with typed getters.

PlayxEnv keeps the loaded values in one (see PlayxEnv.values). It can also wrap any other Map<String, String>, such as remote config:

final config = EnvValues({'RETRIES': '3'});
config.getInt('RETRIES'); // 3

Every type has a maybeGet* getter returning null when the key is missing or the value can't be converted, and a get* getter returning a fallback instead.

Annotations

Constructors

EnvValues([Map<String, String> values = const {}, Set<String> secureKeys = const {}])
Wraps a copy of values. Values of secureKeys are readable with the getters but excluded from all.

Properties

all → Map<String, String>
Every value except secure ones, safe to log or display.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

containsKey(String key) → bool
Whether key has a value.
getBool(String key, {bool fallback = false}) → bool
Returns the value of key as a bool, or fallback.
getDouble(String key, {double fallback = -1}) → double
Returns the value of key as a double, or fallback.
getDuration(String key, {required Duration fallback}) → Duration
Returns the value of key as a Duration, or fallback.
getEnum<T extends Enum>(String key, List<T> values, {required T fallback}) → T
Returns the enum value of values matching the value of key, or fallback.
getInt(String key, {int fallback = -1}) → int
Returns the value of key as an int, or fallback.
getList<T>(String key, {List<T> fallback = const [], T fromJson(dynamic json)?, String separator = ','}) → List<T>
Returns the value of key as a list, or fallback.
getMap(String key, {Map<String, dynamic> fallback = const {}}) → Map<String, dynamic>
Returns the value of key parsed as a JSON object, or fallback.
getNum(String key, {num fallback = -1}) → num
Returns the value of key as a num, or fallback.
getObject<T>(String key, {required T fromJson(dynamic json), required T fallback}) → T
Returns the value of key converted with fromJson, or fallback.
getString(String key, {String fallback = ''}) → String
Returns the value of key, or fallback if it isn't set.
getUri(String key, {required Uri fallback}) → Uri
Returns the value of key as a Uri, or fallback.
isSecure(String key) → bool
Whether key holds a secure value (see PlayxEnvSettings.secureEnv).
maybeGetBool(String key) → bool?
Returns the value of key as a bool: true/1 or false/0 (case-insensitive). null if it isn't set or is anything else.
maybeGetDouble(String key) → double?
Returns the value of key as a double, or null if it isn't set or isn't a number.
maybeGetDuration(String key) → Duration?
Returns the value of key as a Duration, or null if it isn't set or can't be parsed.
maybeGetEnum<T extends Enum>(String key, List<T> values) → T?
Returns the enum value of values whose name matches the value of key (case-insensitive), or null.
maybeGetInt(String key) → int?
Returns the value of key as an int, or null if 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 key as a list, or null if it isn't set or an item can't be converted.
maybeGetMap(String key) → Map<String, dynamic>?
Returns the value of key parsed as a JSON object, or null.
maybeGetNum(String key) → num?
Returns the value of key as a num, or null if it isn't set or isn't a number.
maybeGetObject<T>(String key, {required T fromJson(dynamic json)}) → T?
Returns the value of key parsed as JSON and converted with fromJson, or null if it isn't set, isn't valid JSON, or fromJson throws.
maybeGetString(String key) → String?
Returns the value of key, or null if it isn't set.
maybeGetUri(String key) → Uri?
Returns the value of key as a Uri, or null if it isn't set or can't be parsed.
missingKeys(Iterable<String> keys) → List<String>
Keys of keys without a non-empty value.
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