loadEnv function Null safety

Future<void> loadEnv(
  1. [String path = '.env']
)

load env file

Implementation

Future<void> loadEnv([String path = '.env']) async {
  final env = File(path);
  if (!(await env.exists())) {
    throw '$path does not exist';
  }
  final lines = await env.readAsLines();
  for (final fullLine in lines) {
    final line = fullLine.trim();
    if (line.isNotEmpty && !isAComment(line)) {
      final lineKey = extractKey(line);
      final lineValue = extractValue(line);
      _keys.add(lineKey);
      _values.addAll({lineKey: lineValue});
    }
  }
}