String.fromEnvironment constructor
Value forname in the compilation configuration environment declaration.
The compilation configuration environment is provided by thesurrounding tools which are compiling or running the Dart program.The environment is a mapping from a set of string keys to their associatedstring value.The string value, or lack of a value, associated with anamemust be consistent across all calls toString.fromEnvironment,int.fromEnvironment,bool.fromEnvironment andbool.hasEnvironmentin a single program.
The result of invoking this constructor is the string associated withthe keyname. If no value is associated withname,the result is instead thedefaultValue string, which defaults tothe empty string.
Example of looking up a value:
const String.fromEnvironment("defaultFloo", defaultValue: "no floo")In order to check whether a value is there at all, usebool.hasEnvironment. Example:
const maybeDeclared = bool.hasEnvironment("maybeDeclared") ? String.fromEnvironment("maybeDeclared") : null;The string value, or lack of a value, associated with anamemust be consistent across all calls toString.fromEnvironment,int.fromEnvironment,bool.fromEnvironment andbool.hasEnvironmentin a single program.
This constructor is only guaranteed to work when invoked asconst.It may work as a non-constant invocation on some platforms whichhave access to compiler options at run-time, but most ahead-of-timecompiled platforms will not have this information.
The compilation configuration environment is not the same as theenvironment variables of a POSIX process. Those can be accessed onnative platforms usingPlatform.environment from thedart:io library.
Implementation
external const factory String.fromEnvironment( String name, { String defaultValue = "",});