flutter_dotenv icon indicating copy to clipboard operation
flutter_dotenv copied to clipboard

Is it possible to read the value as constant?

Open holivieri opened this issue 4 years ago • 3 comments

I am reading the values from .env file and I am following the example. I would like to have the option to do this:

static const String apiUrl = env['base_url'];

Because I am using this for retrofit and it requires base_url to be a constant value. This is not possible right now.

holivieri avatar May 25 '21 16:05 holivieri

This isn't possible currently since the .env file is read and the env map is generated only at runtime. I think a simple solution would be to use flutter run --dart-define=base_url=https://www.google.com and retrieve the variable using const String.fromEnvironment('base_url')

ngxingyu avatar May 26 '21 01:05 ngxingyu

i need to read as constant too.

mshamsi502 avatar Jun 15 '21 09:06 mshamsi502

Please, I am having this same issue. Any solution for this?

gettoknowdavid avatar Aug 09 '22 13:08 gettoknowdavid