10

When I execute flutter pub get or pub get, these changes their pubspec.lock sometimes like below.

sdks:
-  dart: ">=2.10.2 <=2.11.0-213.1.beta"
+  dart: ">=2.10.2 <2.11.0"

I thought pub get is nealy equal to CocoaPods command pod install which does not modify lock file.
Why pub get update lock file?

1 Answers1

1

refering to the officiel docummentaion here

this is the answer :

When pub get gets new dependencies, it writes a lockfile to ensure that future gets will use the same versions of those dependencies. Application packages should check in the lockfile to source control; this ensures the application will use the exact same versions of all dependencies for all developers and when deployed to production. Library packages should not check in the lockfile, though, since they’re expected to work with a range of dependency versions.

If a lockfile already exists, pub get uses the versions of dependencies locked in it if possible. If a dependency isn’t locked, pub gets the latest version of that dependency that satisfies all the version constraints.

  • 5
    I can confirm what the OP says; that (at least sometimes) 'pub get' changes the existing pubspec.lock. I built a project and about 12 dep versions were changed in the _existing_ lock file. The quoted docs implies that this will _not_ happen, right? It says: "[an existing lock file] ensures the application will use the exact same versions of all dependencies..." If building changes the lock file, then different builds will use different deps. IOW the docs seem misleading if not wrong. – steve Oct 10 '22 at 15:53