Upgrading projects Flutter SDK, migration to null-safety - compile time errors in packages - flutter

We have decided to upgrade the Flutter version from 1.22 to 2.0 (migrating to null-safety) in an existing project.
We checkout Flutter v2.0.0 and then run the following command:
dart pub upgrade --null-safety
Flutter nicely resolves all dependency conflicts and sets new versions for packages.
Without changing min environment SDK in pubspec.yaml (staying at ">2.10.0 <3.0.0") we fix all breaking changes in the code.
All errors in vs code disappear so we can compile the code. But, when we do compile we get errors from packages e.g. reorderables, fl_chart, flutter_svg etc. stating some classes are undefined. It seems like packages were compiled with a higher SDK version and they weren't set min SDK version to match the one that they were compiled with.
So the package states it can be compiled with Flutter 2.10.0 but in reality, it fails to compile because in this version of Flutter it is missing some necessary imports.
My question is, is this a problem of packages or a problem in my way of processing with migration?
Is it that packages are lacking properly set min SDK?

My conclusion is that most packages are lacking correctly set SDK version constraints. It seems authors usually compile packages for a certain version and do not check min SDK version required. When running dependency resolver it seems to solve dependencies but in compile time it fails.

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.

Version solving for certain package versions failed in flutter

I have received this kind error a couple of time before with different packages, usually i just try a combination of different versions till i finally get a match that works. Is there a way to know what package versions are compatible instead of using the trial error approach which is outright time consuming and exhausting.
Initially i though it could be that one of the packages depends on the other, like in this case maybe flutter_svg depends on a different version of flutter_luban so the version in my pubspec clashes with it, but none of these packages depend on one another after viewing the respective package dependencies.
pub get failed (1; So, because sakaHapa depends on both
flutter_svg ^0.17.4 and flutter_luban ^0.1.13, version solving
failed.)
You can use 'pub outdated' command like below.
https://dart.dev/tools/pub/cmd/pub-outdated
Here is column what means.
Current
The version used in your package, as recorded in pubspec.lock. If the package isn’t in pubspec.lock, the value is -.
Upgradable
The latest version allowed by your pubspec.yaml file. This is the version that dart pub upgrade resolves to. The value is - if the value in the Current column is -.
Resolvable
The latest version that can be resolved, when combined with all other dependencies. This version corresponds to what dart pub upgrade gives you if all version constraints in pubspec.yaml are unbounded. A value of - means that the package won’t be needed.
Latest
The latest version of the package available, excluding prereleases unless you use the option --prereleases.
flutter pub outdated

Error in Flutter while using Provider tool

I am building a basic app using flutter, in which I had to use provider, I added Provider dependencies in pubspec.yaml file but getting this error please help, I added the error below not able to fix this problem I have the latest flutter SDK
To solve this use lower version of Provider dependency as newer version of provider depends on newer version of Flutter SDK and your application's Flutter SDK is old one so it will have compatibility issues, So just degrade the version of dependency or you can also run pub outdated command and it will suggest you compatible version as per your SDK.

Dart: What is the difference between the "Upgradable" and "Resolvable" columns in the output of "dart pub outdated"?

What is the difference between the "Upgradable" and "Resolvable" columns in the output of "dart pub outdated"?
Here is an example of a package that can be upgraded to the latest. The Upgradable, Resolvable, and Latest all match:
url_launcher *6.0.11 6.0.12 6.0.12 6.0.12
Here is an example of a package that is already at the highest resolvable version, but can't be upgraded to the absolute latest version. Presumably another dependency is restricting the resolvability to the latest.
rxdart *0.26.0 *0.26.0 *0.26.0 0.27.2
Here is an example of a package that can't be upgraded any higher but has a Resolvable version that is higher. What does this mean? How is this different from the middle case above?
provider *5.0.0 *5.0.0 6.0.1 6.0.1
In addition to the other very useful posted thoughts, I have learned the following helpful details:
Upgradable refers to the highest version that your direct pubspec will permit, which considers the sdk version and the individual package version (whether to upgrade to just minor or also major). When Upgradable is limited, it can likely be your sdk version holding things back. In my case I was using sdk 2.12, but some packages require 2.14 now (Sep 2021).
From the docs:
The latest version allowed by your pubspec.yaml file. This is the version that dart pub upgrade resolves to. The value is - if the value in the Current column is -.
Resolvable refers to the highest version that all of the other packages' dependencies will allow, in addition to your direct pubspec constraints. When the Resolvable is limited, there is usually one package holding everything back, or a major version holding everything back.
From the docs:
The latest version that can be resolved, when combined with all other dependencies. This version corresponds to what dart pub upgrade gives you if all version constraints in pubspec.yaml are unbounded. A value of - means that the package won’t be needed.
Upgradable means an upgradeable version. Generally, minor version updates can be upgraded directly without modification.
Resolvable can use the version, generally a major version update (the 0.x version may have destructive changes, same as major version), may have incompatible interfaces to the previous version, if you update this version, you may need to change some code
Latest The latest version. If it is inconsistent with the Resolvable version, means the SDK version required by the latest version is inconsistent with the current project
The main difference is that Resolvable mains the version you need to reach to resolve outdated issues in your project and Upgradable mains the version you can update of that package.
To resolve it you must find packages you can update and continue updating until you can update the main package.
You can see it in this link about those concepts: Dart pub outdated

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.