loadFile method

Future<void> loadFile(
  1. String filePath, {
  2. bool overrideExisting = true,
  3. bool expand = true,
})

Load from a .env file path (mobile/desktop/CLI only).

Example: await env.loadFile('.env');

If overrideExisting is false, existing keys are preserved.

Implementation

Future<void> loadFile(
  String filePath, {
  bool overrideExisting = true,
  bool expand = true,
}) async {
  if (kIsWeb) {
    _logger.warn(
      'loadFile("$filePath") ignored on Web. Use loadAsset() instead.',
    );
    return;
  }
  final contents = await platform.readFile(filePath);
  final parsed = _parse(contents);
  _merge(parsed, overrideExisting: overrideExisting);
  if (expand) _expandAll();
  _logger.info('Loaded ${parsed.length} keys from "$filePath".');
}