Flutter android studio --dart-define not working

2.8k Views Asked by At

I am trying to pass arguments using --dart-define in the Android Studio IDE, but I am not able to access in the code.

code is

String.fromEnvironment('ENVIRONMENT', defaultValue: "DEV");

It is returning defaultValue.

enter image description here

2

There are 2 best solutions below

1
Ole On

This is probably a weird gotcha with String.fromEnvironment, from the docs:

This constructor is only guaranteed to work when invoked as const

So this only works if you use

const String.fromEnvironment('ENVIRONMENT', defaultValue: "DEV");
0
ALNAJJAR On

change this

--dart-define=ENVIRONMENT=PROD

to this

--dart-define ENVIRONMENT=PROD