GlobalEnvironment class

A concrete implementation of AbstractEnvironment that represents the default runtime environment for most applications.

It supports:

  • System environment variables via Platform.environment
  • Active and default profile management
  • Placeholder resolution and conversion via the parent class

This class automatically registers a SystemEnvironmentPropertySource under the name 'systemEnvironment'. It also maintains a set of active and default profiles, which can be queried using acceptsProfiles and matchesProfiles.

Example usage:

final env = StandardEnvironment();

env.setActiveProfiles(['dev']);
env.setDefaultProfiles(['default']);

print(env.activeProfiles); // [dev]
print(env.getProperty('PATH')); // system environment variable

if (env.acceptsProfiles(Profiles.of(['dev']))) {
  print('Running in dev mode');
}

The default profile is always 'default' unless overridden explicitly.

Inheritance

Constructors

GlobalEnvironment()
A concrete implementation of AbstractEnvironment that represents the default runtime environment for most applications.
GlobalEnvironment.source(MutablePropertySources propertySources)
A concrete implementation of AbstractEnvironment that represents the default runtime environment for most applications.

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

acceptsProfiles(Profiles profiles) bool
Profile Predicate Evaluation
inherited
addActiveProfile(String profile) → void
Adds an additional active profile to the current set.
inherited
containsProperty(String key) bool
Returns whether the given property key is defined.
inherited
createPropertyResolver(MutablePropertySources propertySources) ConfigurablePropertyResolver
Factory for Property Resolver
inherited
customizePropertySources(MutablePropertySources propertySources) → void
Called during construction to allow subclasses to register default property sources.
override
doGetActiveProfiles() Set<String>
Resolves Active Profiles
inherited
doGetActiveProfilesProperty() String?
Reads Active Profiles Property
inherited
doGetDefaultProfiles() Set<String>
Resolves Default Profiles
inherited
doGetDefaultProfilesProperty() String?
Reads Default Profiles Property
inherited
getActiveProfiles() List<String>
Active Profiles
inherited
getConversionService() → ConfigurableConversionService
Returns the ConfigurableConversionService used to perform type conversions.
inherited
getDefaultProfiles() List<String>
Default Profiles
inherited
getPackageName() String
Represents an abstraction for identifying the package that an object, resource, or service belongs to.
getProperty(String key, [String? defaultValue]) String?
Retrieves the value for the given property key, or null if not found.
inherited
getPropertyAs<T>(String key, Class<T> targetType, [T? defaultValue]) → T?
Retrieves and converts the value of key to the desired type T.
inherited
getPropertyResolver() ConfigurablePropertyResolver
Access to the Property Resolver
inherited
getPropertySources() MutablePropertySources
Returns the MutablePropertySources backing this environment.
inherited
getRequiredProperty(String key) String
Returns the property value for key, or throws IllegalStateException if the property is not defined.
inherited
getRequiredPropertyAs<T>(String key, Class<T> targetType) → T
Retrieves and converts the property key to type T, or throws IllegalStateException if missing or invalid.
inherited
getReservedDefaultProfiles() Set<String>
Reserved Default Profiles
inherited
getSystemEnvironment() Map<String, String>
Returns the environment variables of the underlying OS.
inherited
getSystemProperties() Map<String, String>
Returns the system properties available to the Dart VM (if any), such as those passed via --define or custom bootstrap logic.
inherited
isProfileActive(String profile) bool
Checks Profile Activation
inherited
matchesProfiles(List<String> profileExpressions) bool
Profile Expression Matcher
inherited
merge(ConfigurableEnvironment parent) → void
Merges another ConfigurableEnvironment into this one.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolvePlaceholders(String text) String
Resolves #{...} placeholders in the input text using available properties.
inherited
resolveRequiredPlaceholders(String text) String
Resolves #{...} placeholders in the input text using available properties.
inherited
setActiveProfiles(List<String> profiles) → void
Replaces the current set of active profiles with the given list.
inherited
setConversionService(ConfigurableConversionService conversionService) → void
Replaces the underlying ConfigurableConversionService used for type conversions.
inherited
setDefaultProfiles(List<String> profiles) → void
Specify the set of profiles to be made active by default if no other profiles are explicitly made active through {@link #setActiveProfiles}.
inherited
setEscapeCharacter(Character? escapeCharacter) → void
Sets the escape character used to ignore placeholder prefix and separator.
inherited
setIgnoreUnresolvableNestedPlaceholders(bool ignoreUnresolvableNestedPlaceholders) → void
Enables or disables ignoring unresolvable nested placeholders.
inherited
setPlaceholderPrefix(String placeholderPrefix) → void
Sets the prefix that identifies a placeholder in property values.
inherited
setPlaceholderSuffix(String placeholderSuffix) → void
Sets the suffix that identifies the end of a placeholder in property values.
inherited
setRequiredProperties(List<String> requiredProperties) → void
Sets the list of property names that are required to be present and non-null.
inherited
setValueSeparator(String? valueSeparator) → void
Sets the separator for default values within placeholders.
inherited
suggestions(String key) List<String>
Configuration Suggestions
inherited
suppressGetenvAccess() bool
Suppresses System Environment Access
inherited
toString() String
A string representation of this object.
inherited
validateProfile(String profile) → void
Profile Name Validation
inherited
validateRequiredProperties() → void
Validates that all required properties are present and non-null.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME String
The name used to register the system environment property source.
final
SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME String
The name used to register the system properties property source.
final

Constants

RESERVED_DEFAULT_PROFILE_NAME → const String
The reserved name for the default profile.