To repair our pubspec.lock file during development, I occasionally delete it and run flutter pub get to regenerate it.
What I'm seeing now is, I run flutter pub get and no changes are made to the pubspec.lock file. But, when I delete pubspec.lock and run flutter pub get, git shows that several updates to our packages in the regenerated pubspec.lock file compared to the one that was deleted.
We're all on flutter 2.8. I've tested this with 2.8.0 and 2.8.1 and there are slight differences between the two, but they both update a dozen or more packages. Most updates are patches but a few are minor updates.
Could be something fundamental I'm not understanding about pubspec.lock files? If we're all on the same version of flutter, shouldn't deleting/rebuilding pubspec.lock produce an identical file?
A coworker clued me in. Deleting and regenerating the pubspec.lock file performs a pub upgrade, which is why the packages are newer. Doing a pub get does not run pub upgrade.
Related
I have been using flutter pub get for updating pubspect.yaml
Now I have found that there is a similar command dart pub get
What are the differences between these two commands?
Using the command flutter pub get you are getting dart packages for Flutter.
Using dart pub get you are getting Dart packages.
You can create dart projects without Flutter and there you’ll need use the command dart pub get.
Every Flutter project is a Dart project
but not every Dart project is a Flutter project, because Flutter is a UI kit or framework for building UIs in the Dart programming language.
When dart 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, dart 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. This is the primary difference between dart pub get and dart pub upgrade, which always tries to get the latest versions of all dependencies.
When running flutter pub get (Packages get in IntelliJ or Android Studio) for the first time after adding a package, Flutter saves the concrete package version found in the pubspec.lock lockfile. This ensures that you get the same version again if you, or another developer on your team, run flutter pub get.
I manually deleted a package in External libraries/dart packages. Now I tried to run packages get again. The package(tesseract_ocr) did not appear in External libraries/dart packages.
I tried removing it in pubspec.yaml and re-adding it but did not appear again. I tried deleting .pub-cache and run packages get again. I tried flutter clean, flutter pub cache repair, flutter pub cache add tessarect_ocr and packages get so many times but none of them made tessarect_ocr package reappear in External libraries/dart packages. Please Help. Thanks in advance!
Try
dart pub cache clean
or
flutter pub cache clean
facing the same issue I did the following things:
1.
flutter pub cache clean
which reinstalled all the packages
2. `
flutter pub get
`
which update the dependencies and it works.
I've got a problem where running pub get via the VSCode dart extension doesn't actually get the packages. It doesn't return an error but if I attempt to build my project, it will just continuously tell me my pubspec lock has updated since I last ran pub get.
Running flutter pub get via terminal solves the issue straight way.
Has anyone else experienced this with VSCode?
You can
delete pubspec.lock
then
flutter clean
Reinstall Extensions
Does anyone know if you can do reproducible builds in Flutter? There doesn't seem to be an option to install from the pubspec.lock file. I would of expected something like:
flutter pub get --from-lockfile
The problem is that the pubspec.lock is modified on every run of flutter pub get so I can't easily go back to the previous state of the dependencies at different points in the git history.
I would of expected it to behave like the yarn.lock or package-lock.json which allow you to create reproducible builds of the project.
As mentioned in the doc, pub get should fetch what's in pubspec.lock if the lockfile contains the solution for the dependency requirements and constraints configured in pubspec.yaml. Simply put, if pubspec.yaml and pubspec.lock isn't modified, and neither Dart nor Flutter SDK is upgraded, then pub get should fetch what's listed in pubspec.lock.
If you're still having issues and can be reproducible, you can file an issue here https://github.com/dart-lang/pub/issues - as jonasfj also mentioned in the Comments.
When I add a dependency to the pubspec.yaml file no matter if the IDE runs the pub get command or if I run it manually, it seems like the packages are being imported correctly (or that is what I think), however, if I "change my mind" and delete the package from the pubspec.yaml file, and again pub get, I am unable to build the app anymore, seems like the packages are still linked somehow to the app, even when there is no code related to them, the only way I can get back to work is by cleaning up all... e.g.
cd ios
cd ..
pod deintegrate
flutter clean
flutter pub cache repair
flutter pub get
cd ios
Pod install
Pod repo update
Maybe I am missing a step when working with dependencies.