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:


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:

Answered By – Victor Kwok

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *