How to set version constraints when depending on git packages using Flutter/Dart with versions below 1.0.0?


I am trying to set constraints for git package dependencies with versions below 1.0.0; however, it might also be versions above, but not sure.

Flutter project depends on two packages that we’re hosting on git repositories.

We’re referencing them in our pubspec.yaml as git packages

According to the dependencies docs: ^0.1.2 is equivalent to '>=0.1.2 <0.2.0'

However, it’s always fetching the latest version on github regardless of our version constraints.

Here is how we are referencing package in our pubspec.yaml like this:

      url: ssh://
      ref: develop
      version: ^0.30.0

For example: If we have a branch in this repo that’s versioned 0.32.1 the code above doesn’t seem to work(or rather respect the version constraints) and will simply get 0.32.1 version rather than 0.30.x

Does anyone know how to prevent the flutter pub get command from pulling 0.32.1 in this instance? Is the caret constraint not working because we’re pulling from a git repository maybe?


Judging by the documentation on pubspec.yaml dependencies, Git dependencies use the ref key to specify the version to pull from the repository. dart pub and flutter pub don’t know how to search through your repository for a package version, so the latest commit on the master branch is chosen by default.

Answered By – Ben Konyi

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *