Flutter: Setting constraints for package versions in pubspec.yaml

Viewed 1039

I used share package, share pacakge document said add like this,

 share: ">=0.6.y+x <2.0.0"

Please set your constraint to share: '>=0.6.y+x <2.0.0'

after run pub get, I got this error,

Error on line 65, column 10 of pubspec.yaml: Invalid version constraint: Expected version number after ">=" in ">=0.6.y+x <2.0.0", got "0.6.y+x <2.0.0".

   ╷

65 │   share: ">=0.6.y+x <2.0.0"

   │          ^^^^^^^^^^^^^^^^^^

   ╵
pub get failed (65;    ╵)
2 Answers

You can go to the pub description of the package to get the exact versioning.

Or

Here's a short cut:

Try to give "any" instead of the version number in pubspec.yaml like:

share: any

Then go to pubspec.lock, you will find the latest version that the framework has picked for you.

enter image description here

You might not want to leave it as "any" because if anything changes in the future update, maybe new feature or some deprecation. Your code might crash. It is advised to take the version number from .lock file and pass it in .yaml file (exactly as is it shown in .lock).

Setting constraints:

If you want a specific update of the plugin then you can set constraint for the version number as follows:

plugin_name: '>=1.0.0 <2.0.0' //change these values according to your specs

For your specific requirement:

share: '>=0.6.4+3 <2.0.0'

Actually it says to add it like this in the docs:

share: ^0.6.4+3

This should work.

Related