Null safety migration error: package has unmigrated dependencies. But all my dependencies declare support for null-safety - flutter

Im trying to migrate dart null safety but I get the following error when I run dart migrate
Bad state: Error: package has unmigrated dependencies.
Before migrating your package, we recommend ensuring that every library it
imports (either directly or indirectly) has been migrated to null safety, so
that you will be able to run your unit tests in sound null checking mode. You
are currently importing the following non-null-safe libraries:
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/basic_project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/deferred_components_config.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_driver.dart
file:///C:/flutter/packages/flutter_tools/test/src/test_flutter_command_runner.dart
file:///C:/flutter/packages/flutter_tools/test/src/testbed.dart
package:dwds/data/build_result.dart
package:dwds/data/connect_request.dart
package:dwds/data/debug_event.dart
package:dwds/data/devtools_request.dart
package:dwds/data/error_response.dart
package:dwds/data/extension_request.dart
package:dwds/data/isolate_events.dart
package:dwds/data/register_event.dart
package:dwds/src/debugging/dart_scope.dart
package:dwds/src/debugging/debugger.dart
package:dwds/src/debugging/execution_context.dart
package:dwds/src/debugging/frame_computer.dart
package:dwds/src/debugging/inspector.dart
package:dwds/src/debugging/instance.dart
package:dwds/src/debugging/libraries.dart
package:dwds/src/debugging/location.dart
package:dwds/src/debugging/metadata/class.dart
package:dwds/src/debugging/metadata/function.dart
package:dwds/src/debugging/metadata/module_metadata.dart
package:dwds/src/debugging/metadata/provider.dart
Please upgrade the packages containing these libraries to null safe versions
before continuing. To see what null safe package versions are available, run
the following command: `dart pub outdated --mode=null-safety`.
When I run dart pub outdated --mode=null-safety I got this message and everything seems to be ready for null safety:
C:\flutter\packages\flutter_tools>flutter pub outdated --mode=null-safety
Showing dependencies that are currently not opted in to null-safety.
[✗] indicates versions without null safety support.
[✓] indicates versions opting in to null safety.
All your dependencies declare support for null-safety.
How can I upgrade these packages and migrate to null safety? Appreciate every answer :)

You can use migration helper tool with this command line:
dart migrate
Or you can migrate manually after change min flutter sdk version in pubspec.yaml
environment:
sdk: '>=2.12.0 <3.0.0'
and after this change you need launch this command:
flutter pub get

The tool is listing the following files as non-null-safe:
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/basic_project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/deferred_components_config.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_driver.dart
file:///C:/flutter/packages/flutter_tools/test/src/test_flutter_command_runner.dart
file:///C:/flutter/packages/flutter_tools/test/src/testbed.dart
They belong to Flutter itself:
https://github.com/flutter/flutter/tree/master/packages/flutter_tools/test
So you should update Flutter itself. You can do this in pubspec.yaml:
environment:
sdk: ">=2.15.0 <3.0.0"
flutter: ">=2.10.0" # <= here
I am not sure which version got those files migrated, so try the most recent one that does not break your code too much.

That is because you need update your packages, some packages don't have support for null safety , then you need to check each one of your packages ,
for example.. you can looking some package and on the top say if the package have or not have support for null safety (for example the image ), (sometimes users update in other repositories then check on the issues page from GitHub *if the package don't have support)

Related

flutter migration to null-safety - how fix "Bad state: Error: package has unmigrated dependencies"?

I have a pretty big Flutter project, I'm currently adding null-safety support. My project consists of several parts - the "core" and "client".
"Client" used "core"
environment:
sdk: ">=2.10.0 <3.0.0"
.....
app_core:
path: ../core
First I updated the core with command
dart migrate
Now I when run "dart migrate"(in core) - I get this result:
All sources appear to be already migrated. Nothing to do.
Now I try to update the "client" part, I run the following commands
dart pub outdated --mode=null-safety
[✗] indicates versions without null safety support.
[✓] indicates versions opting in to null safety.
All your dependencies declare support for null-safety.
Next step:
dart pub upgrade --null-safety
Changed 1 dependency!
1 package is discontinued.
24 packages have newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.
No changes to pubspec.yaml!
Next step:
dart pub get
When I run
dart migrate
I get these messages:
Bad state: Error: package has unmigrated dependencies.
Before migrating your package, we recommend ensuring that every library it
(either directly or indirectly) has been migrated to null safety, so
that you will be able to run your unit tests in sound null checking mode. You
are currently importing the following non-null-safe libraries:
...//file list
..............
Please upgrade the packages containing these libraries to null
safe versions
before continuing. To see what null safe package versions are
available, run
the following command: `dart pub outdated --mode=null-safety`.
To skip this check and try to migrate anyway, re-run with the
flag
`--skip-import-check`.
"file list" - is a large list of files from "client" (I did not find any regularity in it). Also, these files have no errors.
What is the reason for these warnings?
How can I fix it? Any advice - I will be grateful.

'package:splashscreen/splashscreen.dart' is legacy, and should not be imported into a null safe library

how to resolve this error of null safe library in splash screen even though I have added dependency most recent one i.e "splashscreen: ^1.3.5"
To import a package without null safety support reduce your flutter version in pubspec.yaml
Replace environment with bellow version
environment:
sdk: ">=2.06.0 <3.0.0"
Note: This is one way to use an external package without null safety support. If it's an existing project check your dependencies for null safety support before migrating.

How to build with a package who doesn't migrate to null safety?

I want to upgrade my flutter version with null safety but some packages didn't migrate.
For example flutter_timeline / capture and share / flutter_dialogflow they did not migrate to null safety
What happen if I upgrade flutter with package not null safety ?
can I still build and release app on store or not?
You can use the flutter run --no-sound-null-safety command to run a project that depends on packages or parts with no sound-null safety yet.
You won't be able to make a release if you upgrade to null safety. You need to either replace the packages or update them yourself

Migrating to Flutter 2 fail

I have a project that is developed with Flutter v1.22.6 and was working great, after updating the flutter to v2.0.0 and reading the documentation, I've found out I can use dart migrate --apply-changes to fix issues that are related to flutter upgrade, By running the command I get dozens of errors and the error ends with:
The migration tool didn't start, due to analysis errors.
The following steps might fix your problem:
1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
2. Run `dart pub get`.
3. Try running `dart migrate` again.
What is the simplest way to migrate the current project to the v2?
The problem is that you have already migrated to a newer version of dart.
You can't migrate your projects from the new version, there is literally nothing to migrate to.
If you want to migrate your older projects (which are without null safety) to a new version, your dart version must be older than 2.12.0 version.
In this case, consider changing the version in your pubspec.yaml file.
environment:
sdk: '>=2.11.0 <3.0.0'
Then run the command in your terminal
> dart migrate --apply-changes
make sure you have following step by step migrate dart 2
and base on your error notification try to set in pubspec.yaml
environment:
# Works in Dart 2 only.
sdk: '>=2.0.0 <3.0.0'

Dart 2.6 and Flutter, Upgrading Dependency

Using Flutter, I am trying to update my dart dependency 2.6.0 but I get an error
Because *project_name* requires SDK version >=2.6.0 <3.0.0, version solving failed.
pub get failed (1)
exit code 1
I want to use the new features that dart offers, such as Extension Methods. How could I go about upgrading my dependency? I have installed the newest stable version of dart on my computer, but regardless I still get that error.
A couple of things that might help:
From this issue, you can try ensuring that you've updated enviroment in your pubspec.yaml file like so:
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Another thing that might help is just double checking the steps in this post or on the dart installation page to ensure that you've updated to the latest version correctly.