Reputation: 126834
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?
Upvotes: 215
Views: 486363
Reputation: 11
I would recommend you all install this package, to maintain the control over the null values in other implementations:
https://pub.dev/packages/flutter_swiper_null_safety/install
Upvotes: 0
Reputation: 801
use this one its worked for me
flutter pub upgrade --null-safety
Upvotes: 1
Reputation: 5068
Easy Solution
If you are using Visual Studio Code, then go to:
Menu File → Preferences → Settings
Search for "Flutter run additional args"
Then click Add Item
Now type --no-sound-null-safety
Click OK.
Upvotes: 59
Reputation: 586
For visual studio code user, add below to settings.json
"dart.flutterRunAdditionalArgs": [
"--no-sound-null-safety"
],
Upvotes: 1
Reputation: 1831
Suppose, in case, anyone gets this error for flutter_html: ^0.8.2
.
Add the following to your pubspec.yaml file:
dependencies:
flutter_html: ^3.0.0-alpha.2
So, it is proved that using any dependency in the project must be the latest version which includes null-safety mechanism.
So, before using "--no-sound-null-safety"
solution, try to search and use the upgraded version of your dependencies.
Upvotes: 1
Reputation: 53
Update your library version to the latest. Nowadays most of the library support.
Upvotes: -1
Reputation: 2853
Adding to creativecreatorormaybenot's answer:
If you're building your APK file or AAB file without sound null safety:
Just do this on your terminal
flutter build apk --split-per-abi --no-sound-null-safety
or
flutter build apk --release --no-sound-null-safety
Upvotes: 3
Reputation: 268114
You run into this error if your code is not fully migrated to null-safety. You can run your "mixed-version" code:
Using the Android Studio IDE
Copy: --no-sound-null-safety
In the 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 the command line
flutter run --no-sound-null-safety
Or to be specific (say in Chrome)
flutter run -d chrome --no-sound-null-safety
Upvotes: 55
Reputation: 329
Open a terminal → use this command → flutter run -d chrome --no-sound-null-safety
.
This should work.
Upvotes: 1
Reputation: 931
The problem happens because the Flutter framework (version 2.2.0 and up) is now supporting sound null safety out of the box, but there are plenty of package and plugins on pub.dev are not migrated to null safety yet, so that's raising the error whenever you run a build
or run
command.
To overcome this issue, add the flag --no-sound-null-safety
in your command.
Example:
flutter build [Target] --no-sound-null-safety
Target arguments:
For Android:
"apk" or "appbundle"
For iOS:
"ipa"
Upvotes: 7
Reputation: 332
Run
dart pub outdated --mode=null-safety
in a terminal and if there is a development dependency update then update the dependency.
That might help.
Upvotes: 8
Reputation: 561
Execute the following command in the terminal to accept all SDK package licenses
flutter doctor --android-licenses
Run the following command in the terminal to check if there are any platform dependencies to complete the set up:
flutter doctor
OUTPUT:
Doctor summary (to see all details, run flutter doctor -v
):
[√] Flutter (Channel dev, 2.2.0-10.1.pre, on Microsoft Windows [Version 10.0.19042.928], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] Visual Studio Code (version 1.55.2)
[√] Connected device (3 available)
• No issues found!
If no issues are found then execute the following command to build an application with unsound null safety
flutter run --no-sound-null-safety
Upvotes: 6
Reputation: 91
If you want run your project with --no-sound-null-safety
, you can add this line to your main.dart
file at the top (first line) with a comment...
// @dart=2.9
Then your project runs with --no-sound-null-safety
...
Upvotes: 9
Reputation: 5605
If using Visual Studio Code, create file .vscode/launch.json in the 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"
]
}
]
}
Upvotes: 50
Reputation: 126834
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.
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
.
Upvotes: 348
Reputation: 757
In case you were using Visual Studio Code and faced it in your unit test.
Visual Studio Code → Preferences → Settings → Search setting, type in "flutter test" → Dart: Flutter Test Additional Args, Add item → Add "--no-sound-null-safety"
Upvotes: 18
Reputation: 1741
In Android Studio:
Run → Edit Configurations → Add Additional Run args → --no-sound-null-safety
Upvotes: 155