Load variables from a .env file into a dart-define (also known as Environment declarations) string and copy it to your IDE Config or to the
clipboard.
Get the latest version from pub:
$ dart pub global activate define_envYou can add the Pub Cache directory to execute the command easily. Learn More
$ define_env # generate dart define string and print it to stdoutYou can skip printing using the --no-print flag
$ define_env -c # generate dart define string and copy to clipboard You can generate and pass the dart define strings to your CI/CD pipeline. To do this with doppler, you can do the following:
dartdefines=`doppler secrets download --format=env --no-file | define_env -f -`
flutter build apk "$dartdefines"Note
- When copying to IDE config,
define_envtries to preserve existing arguments and overwrites only the dart-define statements. This is not thoroughly tested and if you face problems with additional arguments please create an issue.
$ define_env -l # generate dart define string and copy it to launch.jsonBy default, all configurations in launch.json are updated. If you want to update only a specific
configuration, you can do the following
$ define_env -l -n staging # generate dart define string and copy it to "staging" configuration in launch.jsonNote
launch.jsonmay sometimes contain comments. These comments cannot be preserved as of now. If this is important then you should avoid this package
$ define_env -a # generate dart define string and copy it to all run configsBy default, all configurations in .idea/workspace.xml and .run/ are updated. If you want to
update only a specific configuration, you can do the following
$ define_env -a -n staging # generate dart define string and copy it to "staging" configuration onlyYou can add validation for your env by defining a define_env.yaml or adding a define_envsection
to your pubspec.yaml
define_env:
file_path: example
class: MyEnv
fields:
<FIELD_NAME>:
type: enum # String | bool | int | enum
default: # If it is set the field in the env is optional.
enum: # Defines the possible values of the enum. Required field when the type is enum.
values:
- value1
- value2Running define_env will automatically generate an Env Class for you to use in your project. The
class name is defined by class and File Path is defined by file_path in define_env section of
your define_env.yaml or pubspec.yaml. If you don't want a class to be generated, you can pass
the --no-generate flag.
$ define_env --no-generate # Skip Env Class generationUse the issue tracker for bug reports and feature requests.
- Add support for Android Studio and Intellij.
- Add validation support to see warn if any environment variable is missing.
- Generate
Configclass from.envfiles which extract values from environment. - Add Stdin support.
- Make Android Studio and VS Code extensions and plugins to update config automatically
when
.envfiles are updated. - Copy config name directly from
.envfiles. ex.env.stagingis copied to staging config. - Simplify command usage. ex
define_env:printdefine_env:copydefine_env:vscodeetc. - Add support for config files created with
melos