Setup the environment
ShipFlutter uses the dotenv format and strategy for managing environment variables with the help of the envied package.
The concept is simple:
- Given a
.env
file or system environment variables (e.gexport VAR=test
) - And a dart class like:
build_runner
will generate aenv.g.dart
mapping the keys to dart code.
You can then just call Env.key
in your code to get the value.
Setup
The generated project comes with .env.debug
and .env
files with empty values to
allow debug and release envionment. Those files are included in the .gitignore
file
ensuring keys are never included in source control.
To choose between debug or release env use the --release
flag when running the build_runner
In addition, the provided GitHub workflows uses the GitHub secrets to include the keys in the build when building the project using GitHub actions.
Updating a key
-
Modify the key in
.env
and/or.env.debug
-
Clean and Run the
build_runner
(why clean?) -
Update the GitHub secret value
-
Run the app again. The key value should be updated.
Creating a key
Make sure to follow these steps to create a new key.
-
Create a new key in
.env
and.env.debug
-
Create a new static variable in
lib/env/app_env.dart
. For example: -
Run the
build_runner
-
Add the new key to ALL the GitHub workflows that uses envionment variables
-
Store the key in GitHub secrets
-
Use the new key (e.g
Env.keyNew
) in your code