DEV Community


Pass arguments from command line to main in Flutter/Dart?

ashishrawat2911 profile image Ashish Rawat Updated on ・1 min read

You can add the --dart-define= in you flutter run command
Like this

flutter run --dart-define=environment="QA"

Now access the variable in the dart file

const environment =
      String.fromEnvironment('environment', defaultValue: 'Testing');

if you are using flavours you can use this command

 flutter run --flavor core_app -t lib/core_app.dart --dart-define=environment="QA"


Discussion (1)

Editor guide
sultanmyrza profile image
Kasymbekov Sultanmyrza

Didn't worked for me

flutter doctor

Flutter (Channel master, 1.19.0-2.0.pre, on Mac OS X 10.15.5)

--dart-define is not working returning empty value as mentioned above --dart-define got reverted and I also could not get it to work