switchTo method
Switches the active environment to env.
When persistSelection is true, the new selection is written to
SharedPreferences. When false, the switch is in-session only.
Notifies currentNotifier listeners after persisting (or immediately when not persisting).
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(', ')}.',
);
}
if (_persistSelection) await _store.save(env.name);
currentNotifier.value = env;
}