Closed BojanDolic closed 2 years ago
BoxDecoration
is part of Material Design. Do you have uses-material-design: true
in your pubspec.yaml
?
BoxDecoration
is part of Material Design. Do you haveuses-material-design: true
in yourpubspec.yaml
?
Yes I do. Everything was working correctly until now. Autocomplete for widgets worked fine until now. I tried restarting my PC also which didn't help.
I also tried autocomplete in another project and it worked fine. I created empty project and autocomplete also worked so it seems that the issue is tied to this project but what is bothering me is that everything was ok until I launched emulator.
I would not expect the emulator to affect completion. To be honest, this is a puzzle. I don't know what project-specific thing could cause this. Your quickest remedy may be to re-create your project. If you don't want to do that you could try Flutter Pub Get
and Flutter Pub Upgrade
from the Tools > Flutter menu.
Have you ever opened the Android module as its own project in Android Studio (Tools > Flutter > Open Android module in Android Studio
)? That could possibly cause changes (rarely).
I would not expect the emulator to affect completion. To be honest, this is a puzzle. I don't know what project-specific thing could cause this. Your quickest remedy may be to re-create your project. If you don't want to do that you could try
Flutter Pub Get
andFlutter Pub Upgrade
from the Tools > Flutter menu.
Luckily project is not big so I recreated it. I tried Flutter Pub Get
and Flutter Pub Upgrade
with no success.
Have you ever opened the Android module as its own project in Android Studio (
Tools > Flutter > Open Android module in Android Studio
)? That could possibly cause changes (rarely).
I did not. When I go to Tools > Flutter
there is no Open Android module in Android
option shown.
Sorry, but the menu item name changes depending on what is selected in the Project view. In your screen shot, it is named Open for Editing in Android Studio
. Have you used that?
Does completion work as expected in the new project?
Since I'm guessing the answers to these two questions are "no" and "yes", I'm going to see if I can get some help trying to understand what went wrong in the original project. @alexander-doroshko @bwilkerson can you think of anything that might explain the original problem?
I can think of a couple of possibilities, but they all seem very unlikely.
Code completion depends on analysis, and analysis depends on having a valid and up-to-date package_config.json
file. If something caused the file to be corrupted that could explain the problem.
Analysis also depends on being able to read the source for those packages from the .pub-cache
directory. If one of the packages in that directory was corrupted that could potentially cause problems.
Or if some of the files needed for analysis are on a file system that became inaccessible, that could potentially cause problems.
... I ran android emulator inside tool window ( I ran it as a separate window before.)
@stevemessick Is there something different about how the emulator runs when running in a tool window that would explain this?
@BojanDolic If you manually type BoxDecoration
does the analyzer find the class (not produce a diagnostic saying that it's undefined)? Can you navigate to it? If the answer to these is "yes" than analysis appears to be working correctly, so my previous guesses are disproven.
@bwilkerson Yes, I can even click to open its source code. Here is the video, hope it will help:
@BojanDolic When using the project you re-created and running the emulator in the embedded window, does completion work as expected?
@BojanDolic When using the project you re-created and running the emulator in the embedded window, does completion work as expected?
@stevemessick I'm running the emulator as a separate window, I have a fear to run it inside the tool window again because the project grew and I don't want to lose it. Completion works fine in the new project so far.
I tried to recreate the problem in the new project but I couldn't. I tried running the emulator inside the tool window, getting dependencies, but none of that worked.
This is not the first time this happened to me, I was watching a tutorial a couple of weeks ago and I cloned the GitHub repo for the tutorial and after a day or two same thing happened but I was still learning so I thought I messed up something and the project was pretty old in terms of flutter version so I finished that project without completion because it was not big.
I'm sorry @BojanDolic but I didn't quite follow that. If you are concerned about possibly corrupting your project then I'd suggest making a zip file of it, then trying the embedded emulator. If completion gets broken you can delete the project and unzip the zip file to restore.
I can't think of any way using the embedded emulator would affect completion. That's why I'm asking if you can confirm that completion does work with the embedded emulator.
Also, what's the tutorial you were using when you had this problem before?
@stevemessick Okay I ran the emulator inside the tool window and it seems that everything works fine, so I'm really confused about what could stop auto-completion to work.
Also, what's the tutorial you were using when you had this problem before?
I was following a course by Angela Yu about flutter, here is the link to the course: Course
Thanks for the link. Apparently, something can get mis-configured in the project that causes completion to stop working correctly. Completion is complex; it is actually implemented in the Dart plugin, which uses the Dart analysis server to do the heavy lifting of computing suggestions, but also provides a hook that the Flutter plugin uses to support its outline. So, in theory, something could go wrong in any of the three components (Dart plugin, Flutter plugin, Dart analyzer).
It sounds like you are in good shape now. If this happens again, please let us know. For now, I'm going to keep it open and hope I get some time to investigate the tutorial you referenced.
One more thing. I mentioned flutter pub upgrade
earlier, and I see @bwilkerson mentioned a couple symptoms related to that. My hope was that flutter pub upgrade
would rebuild the pub cache, but you may need to do flutter clean
first. If you still have the broken project, could you try doing Flutter Clean
then Flutter Pub Upgrade
-- they are both on the Tools > Flutter
nested menu. Then let us know if anything changed. I appreciate your help tracking this down.
@stevemessick Thanks for suggestion, I tried Flutter Clean
and Flutter Pub Upgrade
and nothing changed, completion still does not work.
If I recall correctly when I opened the emulator in a tool window I also added the image as an asset so I had to change pubspec.yaml
and run pub get
. Maybe that could also point to something.
I imported assets before that but I didn't run the emulator inside the tool window so I thought the emulator caused this issue but apparently it didn't. Hope this helps.
Thanks for the reply. I can't help thinking something is wrong in your pub cache. But aside from completely deleting it I don't know how to determine if that is true. I don't recommend deleting it because it is shared among all Flutter and Dart projects. I'm out of ideas, I'm afraid. At least we got you back to a workable state.
I think I have the same problem and I've put up with it for quite a while now (between half a year and a year I guess) but it would be great to find a solution.
I blew away the pub cache, ./dart_tool and the flutter/dart plugins in Android Studio with no long. All plugins and Android Studio are up to date.
I'd be up for helping out debugging if there are some log files I can look in to or something else.
To be clear: if I type BoxDecoration there is no completion suggested and I can't auto-import. I can navigate to it though.
@stevemessick I've had a look at the IDE logs whilst opening a project where the flutter importing works fine vs one where it is broken. I noticed that when I open the broken project an NPE is thrown which may be relevant:
As a last resort I tried using git bisect
to determine if it was a non-config related change and it was. For some reason quite a while ago I removed flutter as an explicit dependency in my pubspec.yaml 🤦 . Surprisingly everything continued to work except for auto-completions and running flutter tests via right-click.
Adding the following back has made everything work again, hopefully this solves it for someone else too:
dependencies:
flutter:
sdk: flutter
As a last resort I tried using
git bisect
to determine if it was a non-config related change and it was. For some reason quite a while ago I removed flutter as an explicit dependency in my pubspec.yaml 🤦 . Surprisingly everything continued to work except for auto-completions and running flutter tests via right-click.Adding the following back has made everything work again, hopefully this solves it for someone else too:
dependencies: flutter: sdk: flutter
@rorystephenson Thanks for participating and presenting your solution.
Unfortunately, my pubspec.yaml
file has those lines and autocomplete doesn't work. Probably something different happened with my project :(
@BojanDolic Re-reading this just now, I thought of one more thing to try, and another question.
First, the question. You mentioned doing pub get
at one point. Did you do flutter pub get
(which the IDE automatically does if you use the menu)? II don't recall why flutter pub get
is different from pub get
(which is now dart pub get
), but apparently it is.
And then you could try deleting the .dart_tool
directory and doing flutter pub get
to see if that helps.
Sorry for the late response.
I was using pub get
from the pubspec.yaml
file when I imported library.
I deleted .dart_tool
directory and ran flutter pub get
and unfortunately, completion still doesn't work.
Ah, that would have done flutter pub get
so it was doing the right thing. Thanks for the update. I'm out of ideas so I'll leave this open for now.
我也遇到了这样的问题,最近在学习Flutter开发,在创建工程时,Model Name命名了一个大写开头的英文单词,然后自动补全在我学习的这几天就一直是这样,无法自动补全,今天无意间把Model Name文件名改成了小写开头的英文单词,然后在再Android Studio里面打开工程,自动补全就好使了。
According to Google translate, the previous comment is:
I also encountered such a problem. I was learning Flutter development recently. When creating a project, the Model Name named a capitalized English word, and then auto-completion has been like this for the past few days that I have been studying, and it cannot be auto-completed. , today I accidentally changed the Model Name file name to English words starting with lowercase, and then opened the project in Android Studio, and auto-completion was fine.
That's interesting. I'm not sure what Model Name
refers to, but based on the capitalization comment I tried changing the name of main.dart
to Main.dart
and changed the project name in pubspec.yaml
to use camel-case. Neither had an effect on completion, though.
@BojanDolic Could your project be affected by capitalization?
@stevemessick I opened the project to test capitalization. Before I did anything I wanted to test if autocompletion works by some miracle so I went to my screen file and to my surprise, autocompletion now WORKS. I didn't change anything nor did I open the project from the last time.
Before I opened this old project I worked on my current project and updated Kotlin and Dart plugins. I restarted AS and then opened my old project. Is it possible that this somehow fixed it ?
I'm glad it is working, but I don't know what changed to make it work. However, I'm pretty sure that the problem was not in the Flutter plugin, so I'm closing this issue. Thanks for your help!
It recently started to happen to me as well, and I think it was after updating to Flutter 3.0. I hope they fix it with a minor update soon.
It recently started to happen to me as well, and I think it was after updating to Flutter 3.0. I hope they fix it with a minor update soon.
same issue
This just started happening to me after Flutter 3.0, suggestions like setState and overrides such as initState and didChangeDependecies aren't working anymore. May we reopen this please?
I second @thassio-vinicius this is a small issue but it lags the productivity of developer and it needs to be fixed
This just started happening to me after Flutter 3.0, suggestions like setState and overrides such as initState and didChangeDependecies aren't working anymore. May we reopen this please?
Same here. Tried to reset IDE, did not help.
also when I try to auto-import widgets, before it ask me from what I want “material” or “cupertino”. But now autosuggest shows me only one option.
Next ex, I try to type Edg , and there everything but EdgeInsets, and event I typed full word, it lacks of suggestions like EdgeInsets fromLTRB/all etc This happens a while ago
Android Studio Chipmunk | 2021.2.1 Build #AI-212.5712.43.2112.8512546, built on April 28, 2022 Non-Bundled Plugins: Dart (212.5744), org.jetbrains.kotlin (212-1.6.21-release-334-AS5457.46), io.flutter (68.1.2)
For ex VS Code works as before
This just started happening to me after Flutter 3.0, suggestions like setState and overrides such as initState and didChangeDependecies aren't working anymore. May we reopen this please?
Omg, finally I find out someone who has the same issue with a setState. I'm new to programming (and learning Flutter) and can't realize the reason for such thing. So, this is just a glitch of 3.0 and will be fixed? ;)
This just started happening to me after Flutter 3.0, suggestions like setState and overrides such as initState and didChangeDependecies aren't working anymore. May we reopen this please?
Omg, finally I find out someone who has the same issue with a setState. I'm new to programming (and learning Flutter) and can't realize the reason for such thing. So, this is just a glitch of 3.0 and will be fixed? ;)
Should be fixed according to 3.0.2
EDIT: Apparently setState still not working https://github.com/dart-lang/sdk/issues/49027#issuecomment-1152743664
This just started happening to me after Flutter 3.0, suggestions like setState and overrides such as initState and didChangeDependecies aren't working anymore. May we reopen this please?
Omg, finally I find out someone who has the same issue with a setState. I'm new to programming (and learning Flutter) and can't realize the reason for such thing. So, this is just a glitch of 3.0 and will be fixed? ;)
Should be fixed according to 3.0.2
EDIT: Apparently setState still not working dart-lang/sdk#49027 (comment)
Yep, setState still not working, can confirm it.
I'm having problems related to imports too, the auto-complete only works when i force using CTRL + SPACEBAR two times
I'm using Flutter latest version (3.0.2)
As a last resort I tried using
git bisect
to determine if it was a non-config related change and it was. For some reason quite a while ago I removed flutter as an explicit dependency in my pubspec.yaml 🤦 . Surprisingly everything continued to work except for auto-completions and running flutter tests via right-click. Adding the following back has made everything work again, hopefully this solves it for someone else too:dependencies: flutter: sdk: flutter
@rorystephenson Thanks for participating and presenting your solution.
Unfortunately, my
pubspec.yaml
file has those lines and autocomplete doesn't work. Probably something different happened with my project :(
Oh Thanku Man ♥❤💞
Is there a solution? Same problem. Import, setState, etc
Flutter 3.0.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 676cefaaff (9 days ago) • 2022-06-22 11:34:49 -0700 Engine • revision ffe7b86a1e Tools • Dart 2.17.5 • DevTools 2.12.2
I often encounter this problem...
I facing this issue after I upgrade my vscode
Same problem... Android Studio Electric Eel | 2022.1.1 and Flutter 3.7.0
Suggestions not working but autocomplete works using CTRL + SPACEBAR two times
Same problem: Android Studio Hedgehog | 2023.1.1 Patch 2 Flutter 3.19
EDIT: After days of pain, I was finally able to fix: https://stackoverflow.com/a/63096892/17075671
My autocomplete suggestions just stopped working. As an example, none of the widgets show inside suggestions window when I start typing, here is the screenshot when I want to add BoxDecoration:
First image Second image
Steps to Reproduce
I'm not exactly sure how this happened, but the issue started when I ran android emulator inside tool window ( I ran it as a separate window before.)
I created this project few days ago and everything was working fine until now.
Version info
Edit: I tried to fix it with invalidate caches and restart, flutter clean, without emulator running, running emulator outside tool window again. None of those things fixed the problem.