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
Related
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.
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.
2 months ago, I create a project with PascalCase named and it is fine, there is no problem with my project. And now, after I upgrade at flutter stable 2.0.0. The name of my package has a reminder like this
Use lowercase_with_underscores for package names
what should I do? Is there a solution without downgrade the flutter sdk or changing my Package Name?
thanks in advance..
The flutter & dart stranded you must to use the package name must in lower case.
By Using the linter you can disable or ignore the warning
Refer the warning data : https://dart-lang.github.io/linter/lints/file_names.html.
How to disable the warning: https://dart.dev/guides/language/analysis-options#disabling-individual-rules
I hope it will help you.
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?
Creating new Android Studio project get the following exception in Gradle build file:
Cannot resolve symbol 'GradleException'
Gradle still builds successfully, but still shows this error in editor.
What's missing from my project?
Android Studio 3.3.2
Gradle 4.10.1
compileSdkVersion 27
The latest Android SDK does not support GradleException(), instead use FileNotFoundException().
Or for future readers, maybe use RuntimeException (if the issue is not file related).
I found the issue and the solution on this GitHub thread:
https://github.com/flutter/flutter/issues/29608
Note: this answer is no longer up-to-date for newer versions of Android Studio and Gradle. See this answer instead.
Android Studio seems to have various problems that I cannot understand why exist, but they're fixed by invalidating the caches and restarting (from the file menu item). Because the code compiles fine, it seems that this is one of those cases, in which a cache entry somehow ends up, I'm not really sure what specifically happens, but essentially something that prevents it from working properly.
So invalidating the caches and restarting may issues like this, whether it's with Gradle or with Java/Kotlin/Scala/<insert language here>.
For flutter specific,
It won't throw an error. But if you don't want those Red letters then you can replace
GradleException
with
RuntimeException