get method
Returns the value of the environment variable as a String.
- If the variable is found, its string representation is returned.
- If missing, the defaultValue is used if provided.
- If both are unavailable, returns
null
.
If showSuggestions
is true
, it will print a suggestion message
with similar keys if available.
Example
final dbUrl = Env<String>('DATABASE_URL').get();
print('Database URL: $dbUrl');
Implementation
String? get([bool showSuggestions = false]) {
String? value = environment.getProperty(_key, defaultValue.toString());
if (value.isNotNull) {
return value!;
}
if (defaultValue.isNotNull) {
return defaultValue.toString();
}
if (showSuggestions) {
System.out.println(_messageSuggestion);
}
return null;
}