简体   繁体   中英

How to use "--dart-define=" in Flutter test

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM