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
.
Problem: I would like to write some NNBD code which relies on some legacy package, but I can’t seem to make it work.
In this example, statsfl
is a legacy lib, we want to use NNBD in our own code, we don’t care that statsfl
is legacy internally.
If I have a pubspec like this:
environment:
sdk: '>=2.12.0-0 <3.0.0'
dependencies:
flutter:
sdk: flutter
statsfl:
And some code like this:
import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:statsfl/statsfl.dart';
void main() {
runApp(MaterialApp(
builder: (_, __) => _MyPage(),
));
}
class _MyPage extends StatefulWidget {
@override
__MyPageState createState() => __MyPageState();
}
class __MyPageState extends State<_MyPage> {
int i = 10;
@override
Widget build(BuildContext context) {
return StatsFl(child: Container(color: Colors.orange));
}
}
We would expect it to build, but it doesn’t, throwing:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:statsfl
Note: I’m sure where exactly to log this bug as it straddles Flutter and Dart SDKs.
esDotDev
added
the
request
Requests to resolve a particular developer problem
label
Feb 24, 2021
You can pass --no-sound-null-safety
as parameter.
For example:
$ dart --no-sound-null-safety run
$ flutter run --no-sound-null-safety
However, this is not ideal. The ideal is to wait for all dependencies to migrate to null-safety.
Ah I see, so the runtime flag is required to build or run in this unsound mode. Thanks! Before I close this, is there any sort of project specific flag I can enable so I don’t need to pass this for the lifetime of my project? Or some guidance on how to configure tooling btns to pass these flags automatically?
A bit of an aside, Idealism runs up against pragmatism on a daily basis in the trenches Many libs have no active maintainers, and the last thing we want to do mid-production, is take over someone else’s migration. At the same time, it be very nice to to start writing our own NNBD code today.
We have existing apps with 50 deps, it’s just not feasible to worry about all of them, it’s also not a big win for the effort. Packages are generally not having null reference errors, and by far the biggest win for developer productivity with nnbd is within our own /lib code, so it’s a relatively huge lift, for no real rewards from devs POV.
Like in this case, I really could not care less if StatsFl is doing
StatsFl({required child})
or StatsFl({@required child}
or StatsFl({child} : asset(child != null)
, it really is not my concern as an end user. Obviously the compile time errors are preferred, but neither is a big deal from a pragmatic standpoint. Lots of libs are like this, where they just take some child, and upgrading their public interface to NNBD is really fairly pointless, and certainly not something we would defer NNBD usage for if the lib has no active maintainer or they are busy.
@esDotDev In general, we don’t recommend using null safety until your dependencies are all migrated, but as long as you aren’t planning to publish the code on pub (which gets into semver issues) we do support running in this mode. Just be aware that at any point, upgrading your deps may break you (since they may now be opted in, causing new errors in your null safe code that was depending on previously non-null safe libraries). You can of course downgrade your deps again, or just fix the errors. We do recommend publishing null safe packages as a major version bump, so you can also use version constraints on your packages to mitigate this, assuming authors follow our recommendations.
To your question, the easiest way to avoid having to pass the --no-sound-null-safety
flag explicitly is to opt out your entry point (only) out of null safety by marking the file which contains main
with // @dart=2.9
. This will cause the system to auto-detect that you are not fully migrated, and it will run in unsound mode.
Note: you will not be able to use null safety syntax in the file containing main, since it is opted out, so you will either need to «un-migrate» it, or else move your real main
to a different file and make your entry point a dummy main
file (opted out as described above) which does nothing but calls your real main, which can then be opted in:
real_main.dart
// This contains my real entry point, and is opted in void realMain(...) { // Do real stuff, using null safety features };
main.dart
// This contains a dummy entry point, and is opted out // @dart=2.9 import 'real_main.dart'; void main(...) { // Can't use null safety features in this file realMain(...); }
the docs are not explicit enough, after reading them i understood that using // @Dart=2.9 in a dart file part of a flutter project it allows you to use «non null safe» packages in that file only. but it seems that in order to compile the project with «non null packages» you got to place that comment in the main file.
in the docs
«4. Add a language version comment to the top of any Dart files that you don’t want to consider during your current migration:»
source: https://dart.dev/null-safety/unsound-null-safety
How can I set —no-sound-null-safety in Xcode?
In general, we don’t recommend using null safety until your dependencies are all migrated,_
Why? This makes sense for plugin developers, because the plugin might be used in a pure null-safe project. But it doesn’t make any sense for app developers. Many times there are 5% of your plugins you can’t upgrade, and there are still loads of benefits in the meantime to upgrade your /lib code.
I’m really struggling to understand this guidance for app developers. There is basically zero risk to running in this mode, upgrading all your /lib code, and having 1 or 2 legacy deps.
Just be aware that at any point, upgrading your deps may break you (since they may now be opted in, causing new errors in your null safe code that was depending on previously non-null safe libraries).
How? nnbd are always under a major version, as long as we stick on legacy versions, there is no way anything can just break unless we do an explicit version bump, or have no versions specified.
Note: you will not be able to use null safety syntax in the file containing main,
Ah, this is where I got confused as the docs don’t make any distinction here. They say to use this param to enable opt out opf sound-safety, but when you do it, it changes your entire file to legacy which is not expected. Cool trick about moving main though.
Also, fwiw, you can set this up in Android Studio easily enough:
This comment has been minimized.
How can we set in android studio, not for flutter, is for native?
This is for run&debug configuration
how to do same thing for build configuration?
How can we set in xcode?
For Xcode, it will configure this automatically after you run flutter run
once.
or run flutter build ios --debug --config-only --no-sound-null-safety
explain: flutter run
added User-Defined
Build Settings
EXTRA_FRONT_END_OPTIONS=--no-sound-null-safety
in Flutter/Generated.xcconfig
How can we set in android studio, not for flutter, is for native?
For Android Studio run native code when you open android
folder with Android Studio
add extra-front-end-options=--no-sound-null-safety
in your gradle.properties
file
explain: https://stackoverflow.com/a/67751484
How can we set in xcode?
For Xcode, it will configure this automatically after you run
flutter run
once.
or runflutter build ios --debug --config-only --no-sound-null-safety
explain:
flutter run
addedUser-Defined
Build Settings
EXTRA_FRONT_END_OPTIONS=--no-sound-null-safety
in Flutter/Generated.xcconfigHow can we set in android studio, not for flutter, is for native?
For Android Studio run native code when you open
android
folder with Android Studio
addextra-front-end-options=--no-sound-null-safety
in yourgradle.properties
fileexplain: https://stackoverflow.com/a/67751484
thank solution. It’s work for me
Problem: I would like to write some NNBD code which relies on some legacy package, but I can’t seem to make it work.
In this example,
statsfl
is a legacy lib, we want to use NNBD in our own code, we don’t care thatstatsfl
is legacy internally.If I have a pubspec like this:
environment: sdk: '>=2.12.0-0 <3.0.0' dependencies: flutter: sdk: flutter statsfl:
And some code like this:
import 'package:flutter/material.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:statsfl/statsfl.dart'; void main() { runApp(MaterialApp( builder: (_, __) => _MyPage(), )); } class _MyPage extends StatefulWidget { @override __MyPageState createState() => __MyPageState(); } class __MyPageState extends State<_MyPage> { int i = 10; @override Widget build(BuildContext context) { return StatsFl(child: Container(color: Colors.orange)); } }
We would expect it to build, but it doesn’t, throwing:
Error: Cannot run with sound null safety, because the following dependencies don't support null safety: - package:statsfl
Note: I’m sure where exactly to log this bug as it straddles Flutter and Dart SDKs.
Only type // @Dart=2.9 in main.dart file. All problems related to null safety will be solved in other dart files also.
Are you getting ‘Error: Cannot run with sound null safety, because the following dependencies don’t support null safety‘ error while running your app, then have look to solve it.
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:packagename
* Get more help at https://help.gradle.org
BUILD FAILED in 51s
Run your app with additional ‘—no-sound-null-safety’ args.
flutter run --no-sound-null-safety
Platform target Run command:
flutter run -d chrome --no-sound-null-safety
Add the following line at the top of main.dart file
// @dart=2.9
Go to Settings and find «run additional args».
Copy: --no-sound-null-safety
and add into it:
Run your program from «Run Menu«.
Click on «main.dart» at top of IDE, and click on «Edit Configuration«. Note: You need to add Flutter and Dart plugin on android studio, otherwise this menu is not available.
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.
Slide 1
Most trusted JOB oriented professional program
DevOps Certified Professional (DCP)
Take your first step into the world of DevOps with this course, which will help you to learn about the methodologies and tools used to develop, deploy, and operate high-quality software.
Slide 2
DevOps to DevSecOps – Learn the evolution
DevSecOps Certified Professional (DSOCP)
Learn to automate security into a fast-paced DevOps environment using various open-source tools and scripts.
Slide 2
Get certified in the new tech skill to rule the industry
Site Reliability Engineering (SRE) Certified Professional
A method of measuring and achieving reliability through engineering and operations work – developed by Google to manage services.
Slide 2
Master in DevOps Engineering (MDE)
Get enrolled for the most advanced and only course in the WORLD which can make you an expert and proficient Architect in DevOps, DevSecOps and Site Reliability Engineering (SRE) principles together.
Slide 2
Gain expertise and certified yourself
Azure DevOps Solutions Expert
Learn about the DevOps services available on Azure and how you can use them to make your workflow more efficient.
Slide 3
AWS Certified DevOps Professional
Learn about the DevOps services offered by AWS and how you can use them to make your workflow more efficient.
Problem
I’m using flutter_recaptcha_v2: ^0.1.0.
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:flutter_recaptcha_v2
- package:webview_flutter
- package:http
- package:http_parser
For solutions, see https://dart.dev/go/unsound-null-safety
FAILURE: Build failed with an exception.
* Where:
Script 'C:srcflutterpackagesflutter_toolsgradleflutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:srcflutterbinflutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 21s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Solution
If you want run your project with --no-sound-null-safety
so now you add this line your main.dart
file in top(first line) with comment..
// @dart=2.9
then run your project.
Thanks for reading.
Keep Coding.
- Author
- Recent Posts
Email:- contact@DevOpsSchool.com
Hello guys, First of all sorry for being so inactive on site, I was busy with some of my company stuff. Now I’m back with an Error solution tutorial in flutter. Today when I was trying to install a Vibration package from PUB.DEV then I saw a error “Error: Cannot run with sound null safety, because the following dependencies don’t support null safety.” After searching a lot on internet and reading some docs provided from flutter I fount its permanent solution. So let’s get started 🙂 .
Complete Error :-
D:Flutterapp>flutter run
Launching libmain.dart on M2007J20CI in debug mode…
Error: Cannot run with sound null safety, because the following dependencies
don’t support null safety:
– package:vibration
For solutions, see https://dart.dev/go/unsound-null-safety
FAILURE: Build failed with an exception.
* Where:
Script ‘E:Android_SDKflutter_sdkpackagesflutter_toolsgradleflutter.gradle’ line: 1035
* What went wrong:
Execution failed for task ‘:app:compileFlutterBuildDebug’.
> Process ‘command ‘E:Android_SDKflutter_sdkbinflutter.bat” finished with non-zero exit value 1
* Try:
Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output. Run with –scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 28s
Running Gradle task ‘assembleDebug’…
Running Gradle task ‘assembleDebug’… Done 29.4s
Exception: Gradle task assembleDebug failed with exit code 1
Solution for Flutter Error Solution Cannot run with sound null safety, because the following dependencies :-
1. To solve this error all you have to do is add below line in your flutter project’s main.dart file at the top or you can say in the first line of your code as Comment.
2. Now run your project and you’ll see the error is gone. You can read flutter Unsound null safety documentation here for brief information.
Also Read:
Since flutter 2, flutter has enabled null security by default in the configuration. By incorporating null checking into the type system, these errors can be caught during development, so as to prevent crashes caused by the reproduction environment. If empty security is enabled in the current project and the imported third-party plug-in is not adapted, the operation returns the following error.
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:provider
For solutions, see https://dart.dev/go/unsound-null-safety
Restarted application in 341ms.
At this time, you can check whether the new version of the imported plug-in supports empty security. If the plug-in supports empty security, the plug-in platform will mark it as empty security:
if the imported plug-in does not support empty security, you can execute the following commands on the terminal to run the software
flutter run --no-sound-null-safety
Read More:
I have a flutter project, migrated to null safety. After migration i ran my flutter application then it returns me this error
«Cannot run with sound null safety because dependencies don’t support null safety»
Error: Cannot run with sound null safety, because the following dependencies
don’t support null safety:
— package:sticky_headers
For solutions, see https://dart.dev/go/unsound-null-safety
Unhandled exception:
I have read here how to resolve this error https://dart.dev/null-safety/unsound-null-safety
and i have run the application with below command
flutter run --no-sound-null-safety
Then it working proper
How do i make circular icon Inside Button ?
OS Error: A required privilege is not held by the client errno = 1314
How can i use hexadecimal color code in Flutter?
How to display snackbar infinite duration in a flutter application
How do I open a web browser (URL) from my Flutter code?
How to find the Screen orientation in flutter
How to change package name in flutter?
How to handle the code after showDialog is dismissed in Flutter?
How to create Toast in Flutter?
Error : MediaQuery.of() called with a context that does not contain a MediaQuery No MediaQuery ances
How to navigate to new screen without back screen
Cannot run with sound null safety because dependencies don’t support null safety, I have receive
How do i make CachedNetwork image as rounded circle in flutter?
How to set the TextFormField/TextField border color
How to create Gradient background for AppBar in Flutter
How to make shadow for Container widget Flutter?
Navigator operation requested with a context that does not include a Navigator.
How to fix Flutter Bottom OverFlowed error
A RenderFlex overflowed by XX pixels on the bott
Vertical Divider is Not Showing in my Flutter Application
What is Flutter?
How to copy text from Text Widget flutter?
How to convert a String value to double in flutter?
How do we save the data in browser’s cookies using the Flutter web?
How to deactivate back button in flutter?
Flutter Questions and Answers
How do I supply/set an initial value to a text field in Flutter ?
How to change the application launcher icon on Flutter?
Flutter — Vertical Divider — How to add Vertical Divider?
How to place a listview inside a SingleChildScrollView but prevent them from scrolling separately?
How to remove debug banner in flutter?
How do i make TextButton full width in flutter?
How to Close Flutter application Programmatically?
How to fix Flutter: error:MissingPluginException(No implementation found for method)
How do i change the OutlineInputBorder color?
How to handle Scaffold.of() called with a context that does not contain a Scaffold exception?
How to remove Yellow lines under Text Widgets in Flutter?
How can i get document id in Flutter Firestore?
What corresponds to Intent in Flutter?
How to check the given value is a number or not in dart?
How to make a widget Center vertically inside a SingleChildScrollView