Flutter VS Code Quick Fix not suggesting import

4.5k views Asked by At

Everything worked fine until a couple of days ago. Whenever I create new widgets or create some files and want to use them, I don't manually type import package:... but start typing the name of that class and press ctrl + . which provided a list of Quick fixes and always suggested import package:... until recently. No changes to Windows / Flutter / Dart / VS Code have been made except I installed svg-explorer-extension after following this advice (which I would highly doubt affected anything, yet it still updated some x64 c++ distribution something).

Right now, as I try to use existing files (all of them are in */lib folder) in the new files I create, the Quick fix menu provides all except import package:... options which makes the development process slow enough to ask a question here.

enter image description here

The only way to 'recover' that functionality is to run Developer: Reload Window in VS Code which stops the debug session, restarts Dart Analyzer, and everything seems to be okay for the next couple of minutes until it simply disappears.

How to not 'lose' that importing functionality? My project is rather big (22k lines) with 30+ dependencies. I tried reinstalling flutter SDK, flutter, and dart extensions from VS Code and that didn't help.

What suggestions do you have? Is this issue worth filing an issue for Flutter / Dart / Flutter Extension on GitHub?

3

There are 3 answers

3
Syed Waleed On

I was also stucked in this issue and the real answer to this question according to my analysis is : always create new widgets or dart classes within lib folder. You can create different folders such as widgets, screens, models but always create them in lib folder dont create them at the root level. Your problem of import will be solved. Infact VSCode will auto-import them

You can refer to this image below and see how I organized my lib folder [1]: https://i.stack.imgur.com/Yau5i.png

0
worst_coder On

Happening with recently and was fixed with the restart to update option. It was so annoying and wasted my 1 hour searching over google and StackOverflow.

2
Jack' On

If you can't find your import with the "Quick Fix" options, here is what you should do :

  1. Try running flutter pub get

  2. If it doesn't work, reload your window (Ctrl+Alt+P / Cmd+Alt+P and'Reload window')

I recommend to try to get your dependencies firstly, because reloading window generally kills you app.