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.
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.
To set this up in your IDE of choice, you can use:
In both cases, add --no-sound-null-safety
.
For tests, you will want to do the same thing:
In both cases, add --no-sound-null-safety
.
In Android Studio:
Run --> Edit Configurations --> Add Additional Run args --> --no-sound-null-safety
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"
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With