flutter_dotenv
flutter_dotenv copied to clipboard
Fallback from .env
I have this structure with env files: .env .env.staging .env.development .env.production
When I run the app or I make the build I use --dart-define flag and choose the env file I want and it works very good but I need a fallback. For example when I run the app in development, staging or production environment I need a solution for variables that are not described in that environment to have a fallback in .env file and the app to look there in that case.
How can I manage that?
Currently the variables you put in the .env file will not override any existing platform environment variables defined at compile time and set in mergeWith: Platform.environment
, so the env file you use can be though of as a fallback of the mergewith variables as well. Just that the variable won't be constant.
I think I'm looking for the same thing. I would like to define all non-environment-specific values in .env
, and then the specific environment values in each of the subsequent files (development, staging, production), which would overwrite whatever was originally set in the base .env
. But I only want to define a subset of variables in the environment-specific files, so I don't need to manage as many changes. Is there anyway to achieve this right now?