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.
Related
I have a Flutter project with some Infos(less than warnings) in my console in vsCode.
Like : remove unused imports ..
I got a ton of them after months of work. Is there a way to fix them all with a simple command or any tool ?
Thank you.
You can use
dart fix --apply
The dart fix command finds and fixes two types of issues:
Analysis issues identified by dart analyze that have associated automated fixes (sometimes called quick-fixes or code actions)
Outdated API usages when updating to newer releases of the Dart and Flutter SDKs.
See this doc:
https://dart.dev/tools/dart-fix
So I pulled this code from my branch and made few changes using vs code and tried hot reload but the changes are not reflected on the emulator. This is a flutter app using dart. I noticed something that said 'source control - 3 unsaved changes'. Does that have to do anything with this?
1)Make sure you are having a stable internet connection, because sometimes the hot reload and code changes does not work when the internet connection is poor.
2)check the current versions of Flutter, IDE(VS code), Emulator. If you are not updated to the latest version that might be an issue because of the bugs, errors are not fixed in the older versions. command for upgrading the flutter is [flutter upgrade or flutter upgrade --force]
3)Finally in this case if the code is not properly formatted then you can't perform the hot reload function. try the flutter command to format code easily, From the terminal just run [flutter format lib] and it will format all the dart files in the lib directory and subdirectory. You can change lib with whatever directory you like.
4)on top of all still the issue is not resolved try to run command [dart fix --dry-run , dart fix --apply] visit the the official documentation of flutter and dart for more references.
5)I hope this will help you to sort out the issue, if not get back to us. Also replay back which method or solution helps you to solve the issue.
Following these directions, like:
Install the Flutter and Dart plugins
Start VS Code.
Invoke View > Command Palette….
Type “install”, and select Extensions: Install Extensions.
Type “flutter” in the extensions search field, select Flutter in the list, and click Install. This also installs the required Dart plugin.
Validate your setup with the Flutter Doctor
Invoke View > Command Palette….
Type “doctor”, and select the Flutter: Run Flutter Doctor.
Review the output in the OUTPUT pane for any issues. Make sure to select Flutter from the dropdown in the different Output Options.
Step 3 of validate instructions results with OUTPUT:
I did install flutter, and flutter doctor in a new command shell gives result:
What am I missing here? I also try VSCode extension palette command Flutter: New Application Project and that also fails with:
Make sure that you have installed Git and that you can access it from the command line. Check your PATH. Flutter SDK directory should be present there.
If that does not work, you should try to reinstall the dart and flutter extension.
Next Step should be to reinstall flutter.
It occurred to me that my attempt to support multiple flutter versions might be going outside of the conventions supported by the Flutter extension for VSCode.
Here's what's up!... If you think you're smart like me and installed different versions of flutter in folders like c:\src\flutter\1.20.2 and c:\src\flutter\1.22.6, then you can forget it because the extension is smarter than us, and will ignore this regardless of our PATH assignment.
Copying contents of my flutter install from c:\src\flutter\1.22.6 to the parent folder c:\src\flutter resolved my issue. I need to review how to easily support different versions of flutter. Hmmm..
BTW... what I realized in retrospect is that the complaint about git is raised by the extension not finding the .git folder under the flutter folder (i.e. c:\src\flutter) that it presumed as the path to my flutter install. Well duh!! That's because I want flutter to be sourced at the versioned sub-folder (i.e. c:\src\flutter\1.22.6). Oh well.
Some scenarios I am left pondering:
How to correctly support multiple flutter installations while also benefiting from the extension (is there a way to configure this extension or my environment as a whole)?
Are my expectations to support multiple flutter installations unreasonable?
If my expectations are reasonable, and there are no known or documented way to support multiple flutter installations while also using this extension, then perhaps the extension has a bug?
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.
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