Why flutter auto import does not work in VsCode - flutter

Recently the auto import feature for packages and widgets stopped from working, How can I solve it and back it to work? Here an example for import the material flutter package.. in the past when I used to click on fast solve button it was give me an option to import it automatically .Flutter auto import does not work

import material.dart to get the rest of the widget working.

I've had to deal with that for a month or so, and I only managed to solve it a few days ago.
If your problem is anything like mine then it's probably due to one of your settings.
The brute force solution I found is to completely clear your settings.json file and set your preferences again one by one.
Only add those you actually need. I had a lot of them which didn't change much or anything I could notice.
You could also comment out each line one by one to try to find out what exact setting is causing the issue but that's more tedious than doing it all over again.

Related

Weird Intellisense and code suggestions bug VSCode

I am having a weird bug on vscode for which the auto-completion suggestion shows twice and on the first auto-completion, the cursor is not going to the end of the word. I tried to check and play around with autocompletion settings but can't manage to solve this.
One thing I noticed is that if I open the suggestion menu manually and then select it, it works, this happens with the quick suggestions menu.
See the video below for clarity. This is a really annoying issue, can't find anything online about it.
See video here
Possible solutions:
Update your vscode if available.
If that only happens when writing CSS code, maybe that's an extension related issue.
See if that works :)

Change VS Code to auto-import files in flutter relatively

So, here is the problem:
Whenever I am coding with Flutter and Dart, and I use a feature from another file, when I press Tab, VS Code will auto-import the file for me.
The thing is, VS Code will use the package import syntax, like import 'package:<project_name>/<file_path>';. But I prefer relative import syntax.
So, is there a setting I can change in VS Code for Dart to configure it to use relative imports by default?
Thanks!
While importing, you can find both option by tapping on yellow bulb or pressing ctrl+.
Another handy thing, using dart-import extension on Vs-code.
Personally, I am using dart-import extension. There is an extension setting you can turn on to modify imports on save. So, you can have a consistent import structure without needing to choose every single time.
There is a recommendation in effective dart guideline for relative path import usage.

vscode git changes are stuck as fully expanded

I'm having a problem where whenever I make a change in vscode, it is shown fully expanded with the previous change also shown (I realize this description is less than clear, so I've included an image below). If anyone knows how to fix this I'd appreciate it.
For anyone else confused by this, I figured out the solution. For some reason my file was open in the working tree. I'm not sure how I did this, but the problem was fixed by closing the file tab, and reopening the file from the explorer

VS Code Autocomplete Re-imports Package with Full Path

Every time I want to add a widget by selecting it on the autocomplete list from VS Code, let it be a Container, Column, etc., the full path is re-imported. Sometimes the autocomplete list will also show multiple lines for the same widget. import 'package:flutter/material.dart';' is already included on the file.
e.g.
import '../../../../../flutter_linux_v1.0.0-stable/flutter/packages/flutter/lib/src/widgets/framework.dart';
import '../../../../../flutter_linux_v1.0.0-stable/flutter/packages/flutter/lib/src/widgets/container.dart';
Image here: screenshot of autocomplete
It goes away if I run Flutter clean but comes right back. Any ideas to make this go away?
Which extensions are you using? Might there might be some extensions which is overriding flutters default extension behaviour.
You can run code --list-extensions from command line to get all extension installed. You can post it here so that me or someone else can help you out.

Import popup not displaying

In my IntelliJ, auto import pop-up is not displaying although "show import pop-up" is ticked in the settings so I always have to manually type import java.util..... at the top.
I found some similar questions and tried out their solutions, but none of them worked.
I'm new to Java and started using IntelliJ just a week ago, but if I remember correctly the pop-up was displayed at first.
I didn't update any settings and have no clue how I can make it back.
Also, unlike many screenshots of other people's intelliJ, the color of code in my intelliJ are all white except for some keywords which are orange and string which is green.
Not sure if it has something to do with this issue tho.
Could anyone help me find out what could be a problem?
Please follow below instruction, by that you can fix your issues.
1) Go to setting and in the Settings/Preferences dialog (Ctrl+Alt+S), click Editor | General | Auto Import.
2) Select the Add unambiguous imports on the fly checkbox, and apply the changes.
3) After apply the changes , restart the Intellij idea.
It turned out "Power Save Mode" was on, which caused this problem.
I turned it on now and the issue was solved.