flutter_dotenv icon indicating copy to clipboard operation
flutter_dotenv copied to clipboard

Fallback from .env

Open chirita-alex opened this issue 3 years ago • 2 comments

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?

chirita-alex avatar Jun 11 '21 08:06 chirita-alex

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.

ngxingyu avatar Jul 22 '21 23:07 ngxingyu

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?

e-e avatar Aug 06 '21 22:08 e-e