Search code examples
dartdart-null-safety

Dart "--no-sound-null-safety" flag not working


I am trying to run a dart file without null safety using the command line.

The file is:

sandbox.dart

void main() {
    String a;
    print(a);
}

I then run the file using:

$ dart --no-sound-null-safety run sandbox.dart

This is described here: https://dart.dev/null-safety/unsound-null-safety

However, I still get the error:

Error: Non-nullable variable 'a' must be assigned before it can be used.
print(a);

I am using dart version;

Dart SDK version: 2.12.4 (stable) (Thu Apr 15 12:26:53 2021 +0200) on "windows_x64"

Why is it not working?

Note: It works by adding the version string at the top:

// @dart=2.9

But not the command line.


Solution

  • Flutter new versions no longer supporting "--no-sound-null-safety" flag read release note