Flutter: Git branch reference not updating in pubspec.lock

Viewed 624

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?

1 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.

Related