loadDartDefines static method

void loadDartDefines(
  1. Map<String, String> defines, {
  2. bool overwrite = false,
})

Seeds --dart-define values into the runtime environment map.

String.fromEnvironment/bool.hasEnvironment are const constructors — Dart only resolves them for literal keys known at compile time, so BloomEnv cannot look a dart-define up generically by a runtime defines key. Callers declare their known dart-define keys as literals here, and every other BloomEnv accessor can then read them back out of the ordinary runtime map.

If overwrite is true, passed definitions override existing keys (default is false).

Example

BloomEnv.loadDartDefines({
  if (const bool.hasEnvironment('APP_ENV'))
    'APP_ENV': const String.fromEnvironment('APP_ENV'),
  if (const bool.hasEnvironment('PORT'))
    'PORT': const String.fromEnvironment('PORT'),
});

Implementation

static void loadDartDefines(Map<String, String> defines,
        {bool overwrite = false}) =>
    loadMap(defines, overwrite: overwrite);