Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Git branch reference not updating in pubspec.lock

Tags:

flutter

Question to Flutter Community :)

As the question suggests pubspec.lock not updating the current reference of the branch

for example, if I add the below dependency to puspec.yaml like

my_repository:
    git:
      url: https://github.com/jitesh/my_repository.git
      ref: develop

This change my pubspec.lock to

my_repository:
    dependency: "direct main"
    description:
      path: "."
      ref: develop
      resolved-ref: "commit id 1"
      url: "https://github.com/jitesh/my_repository.git"

This seems correct as we get the latest commit, if we added dependency for the first time in puspec.yaml, but if someone pushed some changes to my_repository.git on develop branch, and you want those changes, its not getting even after doing pub get, and giving the same result as

my_repository:
        dependency: "direct main"
        description:
          path: "."
          ref: develop
          resolved-ref: "commit id 1"
          url: "https://github.com/jitesh/my_repository.git"

Ideally, it should change resolved-ref to resolved-ref: "commit id 2" as the latest commits are pushed to develop branch.

The hack, I follow is to upgrade pubspec.lock manually with the latest commit, also I read somewhere that flutter upgrade also does get the latest commits, but it seems to longer process to me to just get one repository commit.

What are the standard practices you guys follow?

like image 419
Jitesh Mohite Avatar asked Oct 25 '25 03:10

Jitesh Mohite


2 Answers

The correct syntax to pull the latest git commit of your package is flutter pub upgrade or flutter packages upgrade (remember to increase your package's version number as well).

The flutter upgrade is unnecessary and serves for upgrading your Flutter version to the latest.

You can also try flutter pub cache repair to reinstall all your packages if the above doesn't help.

like image 91
Bach Avatar answered Oct 26 '25 20:10

Bach


So first things first, when you run pub get, the first source of dependencies flutter looks for is your pubspec.lock file. Lock file is what decides which version and which hash to fetch the package from.

For example if a package p in your pubspec.yaml has a dependency on another package p1 with a caret (^) version constraint, like ^1.2.3, it means that the resolved version of p1 can be any version that is backwards-compatible with the specified version range (e.g., >=1.2.3 <2.0.0).

But if there's already a hash present for p1, when you run flutter pub get, flutter only fetches that hash version and not the updated version of package p1 that's available(as the updated package version might have breaking changes.)

If you're working with git repos, either version them(like 1.2.3), or just comment out the package from yaml, run flutter pub get(this will remove the hash from lock file), uncomment and run again. That will fetch the latest hash since the previous hash has been removed.

Hope that makes sense

like image 31
Saurabh Kumar Avatar answered Oct 26 '25 18:10

Saurabh Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!