loadContent static method
Parses a raw .env formatted content string and loads the resulting key-value pairs into the runtime map.
Ignores blank lines and comment lines starting with #. Strips matching surrounding single or double quotes
from values.
When overwrite is true (the default), existing keys in the environment map are replaced.
When false, previously set keys are preserved.
BloomEnv.loadContent('API_KEY="secret_key_123"\n# Comment\nPORT=9000');
Implementation
static void loadContent(String content, {bool overwrite = true}) {
final lines = content.split('\n');
for (var line in lines) {
line = line.trim();
if (line.isEmpty || line.startsWith('#')) continue;
final eqIdx = line.indexOf('=');
if (eqIdx == -1) continue;
final key = line.substring(0, eqIdx).trim();
var value = line.substring(eqIdx + 1).trim();
// Strip surrounding quotes
if ((value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))) {
if (value.length >= 2) {
value = value.substring(1, value.length - 1);
}
}
if (overwrite || !_env.containsKey(key)) {
_env[key] = value;
}
}
}