load method
Loads environment variables from the env file into a map
Merge with any entries defined in mergeWith
Implementation
Future<void> load(
{String fileName = '.env',
Parser parser = const Parser(),
Map<String, String> mergeWith = const {},
bool isOptional = false}) async {
clean();
List<String> linesFromFile;
try {
linesFromFile = await _getEntriesFromFile(fileName);
} on FileNotFoundError {
if (isOptional) {
linesFromFile = [];
} else {
rethrow;
}
}
final linesFromMergeWith = mergeWith.entries
.map((entry) => "${entry.key}=${entry.value}")
.toList();
final allLines = linesFromMergeWith..addAll(linesFromFile);
final envEntries = parser.parse(allLines);
_envMap.addAll(envEntries);
_isInitialized = true;
}