Flutter: Can I force flutter to install packages from pubspec.lock? - flutter

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.

Related

Deleted pubspec.lock regenerates with newer package versions?

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.

Manually deleted package in External Libraries/Dart Packages not reappearring (Android Studio)

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.

Is it possible to add the latest version of a dependency to pubspec.yaml without finding it myself?

Lets say I am starting a new dart project. I have a few packages on pub.dev I know that I want to use, and I want to use the most recent version of these packages.
Right now, I open my browser and go to pub.dev and find each package, then check the Versions or Installing tab to find out what the latest version is so I can put that in my pubspec.yaml. Then I can run pub get
Using npm, you can run npm install <package> and npm will automatically fetch the latest version of the package and add it to package.json
Is there a pub command, syntax for pubspec.yaml, or something else that will make pub resolve the latest version of a package and use it in my project, without having to manually look up the latest version?
Normally in Flutter, the packages which you want to use need to be added to pubspec.yaml and run pub get. But there are also some IDE plugins like npm.
For example, Pubspec Assist is using on Visual Studio, you can add or update your dependencies without going pub.dev. But you have to know which packages do you want to use at least for a time.
https://marketplace.visualstudio.com/items?itemName=jeroen-meijer.pubspec-assist
Simply enter the following command in the terminal
flutter pub add provider
Of course, where it says provider, put the package you want to install.
The package with the latest version is automatically added to your pubspec.yaml.
Otherwise you can always do what #jamesdlin said and leave the version field empty.

Flutter Xcode build failed due to missing dependencies even when those have been deleted from pubspec.yalm

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.

The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated

I'm running a dart only test in intellij and receiving the following error:
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
I have tried pub get a number of times. Any ideas? I'm on the dev branch of Flutter (anything using Dart 2.7 pretty much fails with the same or a similar error message).
Edit
I think that if you have a path reference dependency in the pubspec.yaml file it will fail.
Anything like the following fails with the above message if you try to run a dart test in IntelliJ.
dependencies:
test_dependency:
path: ../test_dependency
I'm not suggesting this is a fix for everyone, but it did resolve my particular situation.
Just ran into this error after upgrading flutter from 1.22.6 to 2.0.2 and trying to use build_runner: ^1.12.2 and json_serializable: ^4.1.0 to generate json serialization/deserialization classes & methods.
The problem is apparently related to the pub package when used with relative paths for packages as noted in the following github issues:
https://github.com/dart-lang/pub/issues/2806
https://github.com/dart-lang/pub/pull/2830
One of the commenters in issue 2806 mentioned running flutter create . inside the flutter project folder which rebuilds .dart_tool/package_config.json, adding any missing entries, solving the problem.
No one solved this problem so far?
I've found a staightforward solution and it works fine for me.
You need to close your IDE (VSCode in my case), make sure that is completely closed using process-monitor.
Then open a terminal window manualy in your project folder and run "flutter pub get"
After that just start your IDE normaly and ewerything will work fine.