switchTo method
Switches the active environment to env and persists the selection.
Notifies currentNotifier listeners synchronously after persisting. Returns a Future that completes once persistence is confirmed.
Throws EnvSwitchLockedException when the current environment is locked
(i.e. it was included in lockedEnvironments during init).
Throws ArgumentError when env is not one of the registered values
supplied during init.
Implementation
Future<void> switchTo(E env) async {
if (isCurrentLocked) {
throw EnvSwitchLockedException(current.name);
}
if (!_allEnumValues.contains(env)) {
throw ArgumentError.value(
env,
'env',
'Unknown environment "${env.name}". '
'Must be one of: ${_allEnumValues.map((e) => e.name).join(', ')}.',
);
}
await _store.save(env.name);
currentNotifier.value = env;
}