How to upgrade dev dependencies in Flutter - flutter

How can I upgrade my Flutter dev_dependencies? The flutter pub upgrade command doesn't seem to work on those and I don't see a --dev parameter for the command so do I have to update them manually or am I doing something wrong?

Are you familiar with the carat syntax? (e.g., dependency: ^x.y.z)
Carat Syntax documentation
Essentially, the carat indicates to automatically get the most up to date version of that package that is backward compatible with the number you specify. So it will update automatically up to a major version, at which point you will need to manually specify the new version number.

Related

Flutter - What is the recommended way to add plugin version in pubspec.yaml?

Using caret (^) sign -
plugin_name : ^10.0.0
Without using caret (^) sign -
plugin_name : 10.0.0
As The ^ sign is used to automatically use the most up-to-date package from Pub as long as that update won't break anything in the app. However, it is possible that the updated package could introduce new bugs ?
Without the ^ sign will always use the same version of the package from Pub, which can help prevent the introduction of new bugs. If we want to update the package, we will need to manually specify the new version.
So what is the recommended way to add plugin versions to avoid plugin errors / conflicts, while ensuring all plugins remain up-to-date ?
The safest way is to use the explicit version:
plugin_name : 10.0.0
With this you can be shure everything works as it should, if you want to update one package do it by increasing version number by yourself.

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

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.

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

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

Is it possible to add the latest version of a dependency to pubspec.yaml without finding it myself?

Lets say I am starting a new dart project. I have a few packages on pub.dev I know that I want to use, and I want to use the most recent version of these packages.
Right now, I open my browser and go to pub.dev and find each package, then check the Versions or Installing tab to find out what the latest version is so I can put that in my pubspec.yaml. Then I can run pub get
Using npm, you can run npm install <package> and npm will automatically fetch the latest version of the package and add it to package.json
Is there a pub command, syntax for pubspec.yaml, or something else that will make pub resolve the latest version of a package and use it in my project, without having to manually look up the latest version?
Normally in Flutter, the packages which you want to use need to be added to pubspec.yaml and run pub get. But there are also some IDE plugins like npm.
For example, Pubspec Assist is using on Visual Studio, you can add or update your dependencies without going pub.dev. But you have to know which packages do you want to use at least for a time.
https://marketplace.visualstudio.com/items?itemName=jeroen-meijer.pubspec-assist
Simply enter the following command in the terminal
flutter pub add provider
Of course, where it says provider, put the package you want to install.
The package with the latest version is automatically added to your pubspec.yaml.
Otherwise you can always do what #jamesdlin said and leave the version field empty.