4

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

Naveed Jamali
  • 748
  • 8
  • 14

2 Answers2

10

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");
Ole
  • 480
  • 4
  • 11
1

change this

--dart-define=ENVIRONMENT=PROD

to this

--dart-define ENVIRONMENT=PROD
ALNAJJAR
  • 292
  • 3
  • 11