'Cannot run with sound null safety because dependencies doesnot support null safety
I faced the problem when I was using random_string generator dependency for my project and its released version didn't support null safety. So I switched to it's prerelease version implementing null safety and that solved the problem.
Solution 1:[1]
I used this in my dependency:
random_string:^2.1.0
I solved the problem by using:
random_string: ^2.2.0-nullsafety
In my case random_string didnot support the null safety but in your case it can be any dependency. If you want you can also check the pub.dev and type in the dependency you're using. Hope it helps. Thank you.
Solution 2:[2]
Well, take a look at official documentation
Dart provides sound null safety through a combination of static and runtime checks. Each Dart library that opts in to null safety gets all the static checks, with stricter compile-time errors. This is true even in a mixed-version program that contains null-unsafe libraries. You start getting these benefits as soon as you start migrating some of your code to null safety.
However, a mixed-version program can’t have the runtime soundness guarantees that a fully null-safe app has. It’s possible for null to leak out of the null-unsafe libraries into the null-safe code, because preventing that would break the existing behavior of the unmigrated code.
link : https://dart.dev/null-safety/unsound-null-safety
Advice : Since the dependencies you are using does not support null safety, i think the best approach is disable sound nullsafety feature on the run / build. using this flag --no-sound-null-safety
so the running configuration will be like this flutter run --no-sound-null-safety
but this is the best solution so far :
Use compatible dependencies as close as possible it means, when you are having a project that using nullsafety, then use dependencies that already suppor nullsafety.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SAch |
| Solution 2 | Dwi Kurnianto M |
