Reputation: 1039
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 fix
es 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.
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?
Upvotes: 14
Views: 5265
Reputation: 2526
If you can't find your import with the "Quick Fix" options, here is what you should do :
Try running flutter pub get
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.
Upvotes: 5
Reputation: 17
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.
Upvotes: 1
Reputation: 1135
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.sstatic.net/Yau5i.png
Upvotes: -4