get<T> method

T get<T>(
  1. String key, {
  2. T? defaultValue,
})

Implementation

T get<T>(String key, {T? defaultValue}) {
  final currentValue = _environments[key];

  if (currentValue is String) {
    return currentValue.replaceAllMapped(bracketPattern, (match) {
          final variableName = match.group(1);
          return variableName != null
              ? get(variableName)?.toString() ?? ''
              : '';
        })
        as T;
  }

  if (currentValue == null ||
      currentValue is MissingValue && defaultValue != null) {
    return defaultValue as T;
  }

  return currentValue as T;
}