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

Issue

I have followed "Enabling null safety" on dart.dev and also migrated my whole Flutter application to null safety.

Now, I am trying to run it using flutter run. However, it will not start because of the following error:

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:cloud_firestore_web
 - package:firebase_core_web
 - package:shared_preferences
 - package:url_launcher_web
 - package:firebase_auth
 - package:http
 - package:provider
...

For solutions, see https://dart.dev/go/unsound-null-safety
Failed to compile application.

The guide at the URL says that I should "wait for dependencies to migrate before you migrate your package", but I want to use non-nullable by default (NNBD) now.

How can I do that?

Solution

First, you should read through the guide to understand unsound null safety. If you are sure that you want to run your application 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).

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

IDE run arguments/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 Visual Studio 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 Visual Studio Code: search for "Flutter test additional args" in your user settings.

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

Answered By – creativecreatorormaybenot

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

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