optionalString method

String? optionalString(
  1. String key, {
  2. String? defaultValue,
  3. String? description,
})

Reads an optional string environment variable, falling back to defaultValue.

Retrieves key from BloomEnv, trimming whitespace. If the key is absent or empty, returns defaultValue (which defaults to null).

late final String? cdnHost = optionalString('CDN_HOST', defaultValue: 'https://cdn.example.com');

Implementation

String? optionalString(String key,
    {String? defaultValue, String? description}) {
  final val = BloomEnv.getOrNull(key)?.trim();
  if (val == null || val.isEmpty) {
    return defaultValue;
  }
  return val;
}