requireBool method
Reads a required boolean environment variable.
Case-insensitively parses the value:
true:"true","1","yes"false:"false","0","no"
Throws BloomEnvironmentException and records an error in validationErrors if the key is missing, blank, or has any other string value.
late final bool enableSsl = requireBool('ENABLE_SSL');
Implementation
bool requireBool(String key, {String? description}) {
final val = BloomEnv.getOrNull(key)?.trim();
if (val == null || val.isEmpty) {
final desc = description != null ? ' ($description)' : '';
final err =
'Missing required boolean environment variable "$key"$desc.';
_validationErrors.add(err);
throw BloomEnvironmentException(err, errors: [err]);
}
final lower = val.toLowerCase();
if (lower == 'true' || lower == '1' || lower == 'yes') return true;
if (lower == 'false' || lower == '0' || lower == 'no') return false;
final err =
'Environment variable "$key" is not a valid boolean: "$val".';
_validationErrors.add(err);
throw BloomEnvironmentException(err, errors: [err]);
}