In flutter I'm little bit concussion to add package.
Rather than add package with version, is it best way to add package without version in pubspec.yaml file?
Might be, By default it will acquire latest version. But what happen when after adding new version will be available?
You can omit the version or use any
, but it's a good idea to add a version range.
Specifying a version constraint helps to avoid unexpected breaking your app by running flutter packages get
when new dependency versions become available that contain breaking changes (are not compatible with your old code).
You can then intentionally extend the version range for a dependency when you align your code to the new version of the dependency.
Dart and packages are supposed to follow Semantic Versioning which means when an update contains a breaking change, the major version number needs to be incremented.
For versions below 1.0.0
incrementing the minor version number indicates a breaking change.
The ^
is a shortcut to define a version range that indicates the defined version and all later versions that don't contain breaking changes.
So usually you would use
some_dependency: ">=2.0.0 <3.0.0"
or short
some_dependency: ^2.0.0
If some update fixes a bug in 2.1.0
that your application or package depends on you can use
some_dependency: ">=2.1.0 <3.0.0"
or short
some_dependency: ^2.1.0
Specifying a narrow version constraint also can make flutter packages get/upgrade
faster especially when your application contains a lot of dependencies because this reduces the search space for packages get/upgrade
that it needs to traverse to find a compatible set of dependencies.
Please upvote https://github.com/flutter/flutter/issues/12627 to get proper information from flutter packages get/upgrade
when newer dependency versions are available than your constraints allow (like pub get/upgrade
does for non-Flutter Dart projects)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With