load method

Future<void> load({
  1. List<String>? fileNames,
  2. Parser parser = const Parser(),
  3. Map<String, String> mergeWith = const {},
})

Loads environment variables from the list of env files into a map Merge with any entries defined in mergeWith

Implementation

Future<void> load({
  List<String>? fileNames,
  Parser parser = const Parser(),
  Map<String, String> mergeWith = const {},
}) async {
  clean();
  if (fileNames == null) {
    // test mode
    if (isTestEnvironment()) {
      fileNames = const [
        '.env',
        '.env.test',
        '.env.test.local',
      ];
    }
    // release mode
    else if (kReleaseMode) {
      fileNames = const [
        '.env',
        '.env.production',
        '.env.local',
        '.env.production.local',
      ];
    }
    // debug/profiling mode
    else {
      fileNames = const [
        '.env',
        '.env.development',
        '.env.local',
        '.env.development.local',
      ];
    }
  }

  final linesFromEnvFiles = await _getEntriesFromFiles(fileNames);

  processLoadedLines(
    linesFromEnvFiles: linesFromEnvFiles,
    parser: parser,
    mergeWith: mergeWith,
  );
}