Env class abstract final

The primary public interface for envify.

Minimal setup

await Env.init(
  defaultEnv: Environment.production,
  configs: {
    Environment.dev:        'assets/env/.env.dev',
    Environment.staging:    'assets/env/.env.staging',
    Environment.production: 'assets/env/.env.production',
  },
);

Accessing values

final baseUrl  = Env.get('BASE_URL');
final timeout  = Env.getInt('TIMEOUT');
final darkMode = Env.getBool('DARK_MODE');

Switching at runtime

await Env.switchTo(Environment.staging);

All methods delegate to the EnvManager singleton; they throw EnvNotInitializedException if called before init.

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

current Enum
The currently active environment enum value.
no setter
currentEnvData Map<String, String>
All key/value pairs loaded for the currently active environment.
no setter
currentNotifier ValueNotifier
A ValueNotifier that emits the active environment whenever it changes.
no setter
isLocked bool
Whether the currently active environment is locked.
no setter
persistSelection bool
Whether the active environment is saved to and restored from SharedPreferences across sessions.
no setter

Static Methods

get(String key) String
Returns the raw String value for key in the active environment.
getBool(String key) bool
Returns the value for key parsed as a bool.
getDouble(String key) double
Returns the value for key parsed as a double.
getInt(String key) int
Returns the value for key parsed as an int.
getOrElse(String key, String fallback) String
Returns the value for key, or fallback if the key is absent.
init<E extends Enum>({required E defaultEnv, required Map<E, String> configs, Set<E>? lockedEnvironments, bool persistSelection = true, EnvLoader? loader, EnvStore? store}) Future<void>
Initialises envify, loading all .env assets and restoring any previously persisted environment selection.
setPersistSelection(bool persist) Future<void>
Changes the persist mode at runtime.
switchTo(Enum env) Future<void>
Switches the active environment to env and persists the selection.