Update flutter dependencies in /.pub-cache - flutter

I erased in my folder .pub-cache/hosted/pub.dartlang.org/this_plugin
What is the command to update the dependencies inside pubsec.yaml? I believe it is
flutter packages get
The folder under .pub-cache is still not up to date.
Note: there was a pubspec.lock that I deleted

Disclaimer: By running the command below, have a really fast internet
connection or be ready to lose one hour of productive hours. ( it will
redownload every package every installed on your pc, and I mean each
and all of the versions of each packages)~TSR
flutter pub cache repair
or delete /Users/xxxxxxx/development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+3/ and run flutter packages get again.
if all the above things fail delete the cache folder or also check the version updated in the lock file (some time lock give me the problem with updating the version number)
PS:
Why flutter pub cache repair download every package version previously used?

Remove the package from dependencies in pubspec.yaml, run flutter packages get. And then add the package to dependencies again and running flutter packages get.This process has solved the problem for me in the past.

This steps worked for me
Delete the pubspec.lock file then run the command flutter pub get again.

Clearing the projects cache
You can empty the entire projects cache to reclaim extra disk space or remove problematic packages.
run flutter pub cache clean in terminal at project directory

The below steps worked for me.
Flutter installation corrupted
The Flutter install directory is in an inconsistent state and that causes all kinds of troubles.
Causes
Unclear
Ways to fix
Run the following commands in the Flutter install directory:
git clean -xfd
git stash save --keep-index
git stash drop
git pull
flutter doctor
Corrupted cache
Especially with plugin packages, it was seen several times that the package in the pub cache was corrupted.
Symptoms
Usually syntax errors at build time about code in dependencies.
Causes
Unknown.
IDEs or editors used by developers might not prevent editing plugin files and when they navigate into plugin code they might accidentally modify the code.
Ways to fix
Run flutter pub cache repair
This might take quite some time and re-downloads every package in the cache, even outdated versions that might not be used anymore by any project on disk.
Delete ~/.pub-cache/hosted and/or ~/.pub-cache/git (for Git dependencies). This requires running flutter packages to get in all active projects on your machine afterward.
Delete a specific package or package version. Look up the exact path in the cache for a specific package in the .packages file of your project. For example for firebase_auth
Reference: https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#flutter-installation-corrupted

Related

Project files can't see library

There are many libraries I use every day from pub and they work. But today I run into a problem with qr_code_scanner. After installing it with flutter pub add qr_code_scanner and running flutter pub get, I get in code:
Same with auto import for classes from this file like QRViewController. What I also did is running flutter upgrade, flutter clean and everything else that came to my mind - still getting this error with that package.
Any other thoughts how can I solve it?
Some of the packages you are using are upgraded to flutter3 and some are still Flutter version < 3. Which is why you might be facing an issue. If you are trying to build an older project I would recommend you to downgrade your package versions which is compatible with flutter < 3 and use flutter version < 3. If you are adding any packages through pub add you might get an error if the pub get is not resolved. Please check the same in terminal.
For anyone who will have the same issue, I found a workaround. I've also tried few other libraries that beside the fact was installed couldn't access them from anywhere in code.
So after all every pub.dev lib is just the code right? You can download the source file and add it into your lib folder. Well, you have to upgrade it manually if needed but at the end it works and that's the main goal!
EDIT:
Another possible solution, as I found out, I did reset my Mac, upgraded environment (VS Code), done flutter clean and flutter pub get and looks like it's working as it should without mentioned workaround so probably the issue was around the coding environment rather than with Flutter and fetched libraries.

How to install and run flutter without network connection?

I installed flutter on a machine with a network, all tests and commands ( doctor, create, test ) run without problems. Then he took the directory where flutter was located and transferred it to a machine without an Internet connection. But with any call to flutter, it goes into
Running "flutter pub get" in flutter_tools.."
And does not leave this process. If you run it with the -vv flag, you can see that there is Resolving dependencies... The --offline flag does not help. I also tried to take .config, .pub-cache, .flutter from the machine where there is a connection and transfer it to the working one, but this did not help either. The question is, is there anything else that can be dragged and dropped as a dependency, or is there another way to run flutter offline?
Both machines are running Debian 9.
As I thought, all this is possible. The problem is in the wrong paths. When transferring the flutter working directory to another PC, you need to make sure that the paths are identical. Because in *packages/flutter_tools/ files there are many links in files on paths that correspond to downloads from the first machine.
Total what needs to be done:
Update flutter and dart
Run flutter precache
Copy the entire directory where flutter is located and ~$HOME/.pub-cache
Create the same path on the new machine and transfer the files.
Perform all necessary operations with the --offline flag

Package is not showing up in the dart packages folder even though it is installed

I have been having issues with installing this package https://pub.dev/packages/graphql_flutter/install one of it's dependencies is this graphql package https://pub.dev/packages/graphql. When i do pub get it installs en shows everything expect for the graphql package in the dart packages folders. I have tried to install the graphql package separately but the package still doesnt show up than. And the import still gives the error "Target of URI doesn't exist: 'package:graphql/client.dart'." But it does show up in flutter/.pub-cache/hosted/pub.dartlang.org so i dont understand why it doesnt show in my project. I have tried using flutter clean, flutter clean pub cache and androidstudio's invalidate caches/restart function to no avail. I have also tried restarting android studio and my pc multiple times. I have also tried it with androidstudio run as admin.
This is my pubspec.yaml
this is part of my Dart packages folder as you can see it does not show
And this is the pub.dartlang.org folder on my pc
It ended up getting randomly fixed after 3 days. I just started android studio up and tried it again and suddenly it worked. No idea what fixed it in the end
Seen this issue a few times. Open Task manager in windows and check for adb.exe. There should be one copy running. I had 2 copies so removed 1 and restarted the other.
right-click --> end task for both.
All ok then.
Reloading VS code worked for me..
Reloading can be done ---> Command + R for Mac.

Flutter - How to switch flutter channel without downloading flutter & dart sdk every time

Currently i was trying on flutter web for which i needed to work on flutter master channel. But, then i needed to work on my other projects. On them i am working on flutter stable channel.
But, every time i switch my flutter channel using the command "flutter channel stable" or "flutter channel master", It keeps re-downloading sdk and other tools every time.
Currently, i have downloaded stable flutter sdk and stable dart sdk.
I have moved them in a "FlutterSDK" folder with two other folders "stable" & "master" in it. Both folders contains the stable flutter & dart sdk.
But, it keeps re-downloading the resources. What am i doing wrong ?
Can anyone help with this?
Thanks.
You may have a look on Flutter FVM. This tool allows you to manage multiple channels and releases, and caches these versions locally, so you don't have to wait for a full setup every time you want to switch versions.
Solution for Linux(possibly MacOS)
Download pure flutter
Unzip it.
Change the name to "flutter-stable"
Make a copy of this folder.
Change the name of the copy to "flutter-web" (for example).
Open the .bashrc file in your home folder.
Add two lines at the end:
alias flutter = "{your directory path}/flutter-stable/flutter"
alias flutter-web = "{your path to folder}/flutter-web/flutter"
Restart the computer (or log out and log back in).
Enter in the terminal "flutter doctor -v" and "flutter-web doctor -v" (to download the necessary files)
Enter "flutter-web channel" in the terminal to find out the current branch (marked with a star)
In order to change the branch, enter the "flutter-web channel master" in the terminal (instead of the master, you can choose any other)
Enter "flutter-web upgrade" in the terminal to update the branch.
Done. If you need a stable version, then use flutter (flutter pub get), if for the web, then flutter-web (flutter-web pub get)
Ps if you already have a stable version, then:
skip point 3 and 4. (you don't need to make copies, just download a clean flutter sdk, unpack, rename it, and put it next to the existing one)
remove the path to the flutter sdk from the environment so that there is no name conflict (requires a reboot)

Why does flutter packages get fail? Same directory cloned from github but on one pc package get fail

Cloned from github a flutter repo onto Laptop(win10) and Desktop (win7) but on Desktop package get fail with error code 1
First two images show success on laptop pc.
See Below Desktop Fails to get packages.
Where should I correct this on Desktop?
However, I can create new app without any error on Desktop.
Please help, Thank you.
I deleted the two log files and also pubspec.lock file and run Flutter Get Packages. This Resolved the issue. This agonizing error ate up few hours.
I tried
flutter clean
flutter packages get
it worked