skip to Main Content

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

Answers


  1. 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");
    
    Login or Signup to reply.
  2. change this

    --dart-define=ENVIRONMENT=PROD
    

    to this

    --dart-define ENVIRONMENT=PROD
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search