getString method

String getString(
  1. String key, [
  2. String? defaultValue
])

Get a String associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. If no default value is provided and throwExceptionOnMissing is true then a NoSuchElementException is thrown. If throwExceptionOnMissing is false then an empty String '' is returned. If the value exists then interpolation is performed before returning it. The returned String is never null.

Implementation

String getString(String key, [String? defaultValue]) {
  Object? value = _resolveContainerStore(key);

  if (value == null) {
    if (defaultValue != null) {
      return defaultValue;
    } else {
      if (throwExceptionOnMissing) {
        throw NoSuchElementException(
            "$key doesn't map to an existing object");
      } else {
        return '';
      }
    }
  } else {
    Object? result = interpolate(value);
    return result == null ? '' : result.toString();
  }
}