DebugEnvironmentManager class
Environment manager for debugging.
Usage:
// Register environments
DebugEnvironmentManager.registerAll([
Environment(id: 'dev', name: 'Development', baseUrl: 'https://dev.api.com'),
Environment(id: 'staging', name: 'Staging', baseUrl: 'https://staging.api.com'),
Environment(id: 'prod', name: 'Production', baseUrl: 'https://api.com'),
]);
// Set current environment
DebugEnvironmentManager.setEnvironment('dev');
// Get current environment
final env = DebugEnvironmentManager.currentEnvironment;
print(env?.baseUrl); // https://dev.api.com
// Listen to changes
DebugEnvironmentManager.addListener((env) {
print('Environment changed to: ${env.name}');
});
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
-
allEnvironments
→ List<
Environment> -
Get all registered environments.
no setter
- currentBaseUrl → String?
-
Get the current base URL.
no setter
- currentEnvironment → Environment?
-
Get the current active environment.
no setter
- isDevelopment → bool
-
Check if current environment is development.
no setter
- isProduction → bool
-
Check if current environment is production.
no setter
- isStaging → bool
-
Check if current environment is staging.
no setter
Static Methods
-
addListener(
void listener(Environment)) → void - Add a listener for environment changes.
-
clear(
) → void - Clear all environments.
-
exists(
String id) → bool - Check if an environment exists.
-
export(
) → Map< String, dynamic> - Export environments as JSON.
-
exportJson(
) → String - Export as JSON string.
-
getConfig<
T> (String key) → T? - Get config value from current environment.
-
getEnvironment(
String id) → Environment? - Get a specific environment by ID.
-
import(
Map< String, dynamic> data) → void - Import environments from JSON.
-
importJson(
String jsonString) → void - Import from JSON string.
-
register(
Environment environment) → void - Register a new environment.
-
registerAll(
List< Environment> environments) → void - Register multiple environments at once.
-
removeListener(
void listener(Environment)) → void - Remove a listener.
-
setEnvironment(
String id) → void - Set the current environment by ID.
-
unregister(
String id) → void - Remove an environment.