Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run with sound null safety because dependencies don't support null safety

People also ask

How do you fix Cannot run with sound null safety because the following dependencies don't support null safety?

Copy: --no-sound-null-safety and add into "additional run args". Run your app with "Run/Play" Button or from "Run" Menu. In this way, you can solve "Error: Cannot run with sound null safety, because the following dependencies don't support null safety" error on Flutter project.

How do you add a null safe in VS code?

Search for "Flutter run additional args" in your user settings and add --no-sound-null-safety . Paste the command in the item field and click ok as we already added one command. Search for "Flutter test additional args" in your user settings and add --no-sound-null-safety .


First, you should read through the guide to understand unsound null safety.
If you are sure that you want to run your app with unsound null safety, you can use the following command:

flutter run --no-sound-null-safety

The --no-sound-null-safety option is not documented in the article, however, I have not experienced any problems with it for the last few months (and especially not since the whole Flutter framework has been migrated to null safety).

Edit: the documentation has now been updated to include this. See Testing or running mixed-version programs.

IDE run args/configuration

To set this up in your IDE of choice, you can use:

  • In IntelliJ/Android Studio: "Edit Configurations" (in your run configurations) → "Additional run args".
  • In VS Code: search for "Flutter run additional args" in your user settings.

In both cases, add --no-sound-null-safety.

Test configuration

For tests, you will want to do the same thing:

  • In IntelliJ/Android Studio: "Edit Configurations" (in your run configurations) → "Additional args".
  • In VS Code: search for "Flutter test additional args" in your user settings.

In both cases, add --no-sound-null-safety.


In Android Studio:

Run --> Edit Configurations --> Add Additional Run args --> --no-sound-null-safety

enter image description here


If using vscode. create .vscode/launch.json in project root and add

"args": [
         "--no-sound-null-safety"
        ]

Complete code:

{
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
                {
                        "name": "YOUR_PROJECT_NAME",
                        "program": "lib/main.dart",
                        "request": "launch",
                        "type": "dart",
                        "args": [
                                "--no-sound-null-safety"
                            ]
                }
        ]
}

If you are using VS Code

Then Goto

File => Preferences => Settings

Search for "Flutter run additional args"

then click Add Item

now type --no-sound-null-safety

click ok


In case you were using VSCode and faced it in your unit test.

Code => Preferences => Settings => Search setting, type in "flutter test" => Dart: Flutter Test Additional Args, Add item => Add "--no-sound-null-safety"

--no-sound-null-safety description picture


You run into this error if your code is not fully migrated to null-safety. You can run your "mixed-version" code:

  • Using IDE

    Copy: --no-sound-null-safety

    enter image description here

    enter image description here

  • In Dart file

    Add // @dart=2.9 at the top in your main.dart file and run the app using the Play ► icon.

    // @dart=2.9
    import 'package:flutter/material.dart';
    
    void main() {
      //...
    }
    
  • Using command line

    flutter run --no-sound-null-safety
    

    or to be specific (say in chrome)

    flutter run -d chrome --no-sound-null-safety