-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
I was looking into setting up different environment configurations for an application that is both a mobile app and a web app.
The usual setup for an environment config involves an .env file as an asset for the app.
For multiple environments / .env files, different entrypoints can be used with the -t flag for build & run.
However, switching between these targets has one problem.
In terms of developer experience, I'd expect to be able to just change the argument for -t and nothing else.
In practice, I'd have to edit the pubspec.yaml before each build / run.
Otherwise I would be including .env files that are not used at runtime.
(I.e. when running with .env.test, you don't need/want .env.dev in your assets,
both to reduce file size and for security reasons)
Example:
For dev
flutter:
assets:
- .env.dev
# - .env.test
For test
flutter:
assets:
# - .env.dev
- .env.test
Proposal
There should be a way to conditionally include an asset, based on a predefined condition.
Perhaps there could be an extra pubspec section or file that allows developers to setup an environment specific part.
Example:
# pubspec.yaml
flutter:
assets:
- shared_asset.png
environment-configuration:
my-custom-dev-env: # Entries with custom keys, but with the same structure as a regular app (assets / fonts / etc)?
assets:
- .env.dev
my-custom-test-env:
assets:
- .env.test
Switching between environment-configuration entries could be done using a new flag for flutter build / flutter run?
By default nothing would be included.