getBool method

bool getBool(
  1. String name, {
  2. bool? fallback,
})

Load the enviroment variable value as a bool

If variable with name does not exist then fallback will be used. However if also no fallback is supplied an error will occur.

Furthermore an FormatException will be thrown if the variable with name exists but can not be parsed as a bool.

Implementation

bool getBool(String name, {bool? fallback}) {
  final value = maybeGet(name);
  assert(value != null || fallback != null,
      'A non-null fallback is required for missing entries');
  if (value != null) {
    if (['true', '1'].contains(value.toLowerCase())) {
      return true;
    } else if (['false', '0'].contains(value.toLowerCase())) {
      return false;
    } else {
      throw const FormatException('Could not parse as a bool');
    }
  }

  return fallback!;
}