Home > database >  How to use "--dart-define=" in Flutter test
How to use "--dart-define=" in Flutter test

Time:12-10

I'm using flutter test with --dart-define option as follows:

# code to run the test
flutter test --machine --start-paused --plain-name "" --dart-define=SOMEENVVAR=123 test/rovaf_client_test.dart

but the problem is that I can't use this environment variable as follows:

print(String.fromEnvironment("SOMEENVVAR"));

this just prints out nothing.

Is there any way to use environment variable or pass parameters for flutter run test command? Thanks!

CodePudding user response:

You need a const for environment variable.

print(const String.fromEnvironment("SOMEENVVAR"));

Please refer to this: https://github.com/flutter/flutter/issues/55870#issuecomment-620776138

  • Related