Sdk: Dart Analyzer in Flutter stops suggesting Classes as you type (and doesn't import them)

Created on 26 Nov 2020  Â·  3Comments  Â·  Source: dart-lang/sdk

I am building an app in Flutter and the problem I started facing I described on Stackoverflow

Basically, at some point, as I launch my flutter project, after a couple of minutes the Dart Analyzer stops suggesting autocompletion of the imported classes (widgets), for example when I type Text - it doesn't suggest the Text widget with a description but the IntelliSense still recognizes it once I finish the widget name. The biggest problem though is with imports. If I type something I already created (for example static class ThemeConstants.), it neither suggests the full class name nor it auto-imports that object. The funniest is that when I created a fresh new project, everything works as it should (it suggests import and auto-completion for the object names).

Unfortunately, my project is not shareable but it has 21k lines of code and ~30 dependencies. Everything worked fine until I cleared some cache on the computer (that's the only thing that went differently).

I tried running Dart: Capture Logs command in VS Code and in the project that I just created, I tried capturing the time when I type "Text" and right after entry with the following log

[6:40:56 PM] [Analyzer] [Info] ==> {"id":"93","method":"edit.getAvailableRefactorings","params":{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","length":0,"offset":4504},"clientRequestTime":1606354856878}
[6:40:57 PM] [Analyzer] [Info] <== {"id":"91","result":{"fixes":[{"error":{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":4501,"length":3,"startLine":107,"startColumn":13},"message":"Undefined name 'Tex'.","correction":"Try correcting the name to one that is defined, or defining the name.","code":"undefined_identifier","url":"https://dart.dev/tools/diagnostic-messages#undefined_identifier","hasFix":true},"fixes":[{"message":"Create class 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","fileStamp":0,"edits":[{"offset":4790,"length":0,"replacement":"\r\n\r\nclass Tex {\n}"}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":4800},{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":4501}],"length":3,"suggestions":[]}],"id":"dart.fix.create.class"},{"message":"Create getter 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","fileStamp":0,"edits":[{"offset":2001,"length":0,"replacement":"\r\n\r\n  get Tex => null;"}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":2011}],"length":3,"suggestions":[]}],"id":"dart.fix.create.getter"},{"message":"Create local variable 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","fileStamp":0,"edits":[{"offset":2888,"length":0,"replacement":"var Tex;\r\n    "}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":2892},{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":4515}],"length":3,"suggestions":[]}],"id":"dart.fix.create.localVariable"},{"message":"Create mixin 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","fileStamp":0,"edits":[{"offset":4790,"length":0,"replacement":"\r\n\r\nmixin Tex {\n}"}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":4800},{"file":"D:\\Work\\Flutter\\zzzzz\\lib\\main.dart","offset":4501}],"length"…
[6:40:57 PM] [Analyzer] [Info] <== {"id":"93","result":{"kinds":["EXTRACT_LOCAL_VARIABLE","EXTRACT_METHOD"]}}

it's followed by

[6:40:56 PM] [Analyzer] [Info] <== {"id":"89","result":{"kinds":["EXTRACT_LOCAL_VARIABLE","EXTRACT_METHOD"]}}
[6:40:56 PM] [Analyzer] [Info] <== {"id":"83","result":{"fixes":[]}}
[6:40:56 PM] [Analyzer] [Info] <== {"id":"88","result":{"assists":[]}}
[6:40:56 PM] [Analyzer] [Info] <== {"id":"90","result":{"completion":"Text","change":{"message":"","edits":[],"linkedEditGroups":[]}}}

Whereas the main project Analyzer stopped at this line and didn't do anything with "Text"

[6:42:03 PM] [Analyzer] [Info] <== {"id":"8762","result":{"fixes":[{"error":{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":24506,"length":3,"startLine":414,"startColumn":39},"message":"Undefined name 'Tex'.","correction":"Try correcting the name to one that is defined, or defining the name.","code":"undefined_identifier","url":"https://dart.dev/tools/diagnostic-messages#undefined_identifier","hasFix":true},"fixes":[{"message":"Create class 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","fileStamp":0,"edits":[{"offset":30683,"length":0,"replacement":"\r\n\r\nclass Tex {\n}"}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":30693},{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":24506}],"length":3,"suggestions":[]}],"id":"dart.fix.create.class"},{"message":"Create getter 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","fileStamp":0,"edits":[{"offset":792,"length":0,"replacement":"\r\n\r\n  get Tex => null;"}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":802}],"length":3,"suggestions":[]}],"id":"dart.fix.create.getter"},{"message":"Create local variable 'Tex'","edits":[{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","fileStamp":0,"edits":[{"offset":1475,"length":0,"replacement":"var Tex;\r\n            "}]}],"linkedEditGroups":[{"positions":[{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":1479},{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":24528}],"length":3,"suggestions":[]}],"id":"dart.fix.create.localVariab…
[6:42:03 PM] [Analyzer] [Info] <== {"id":"8764","result":{"kinds":["EXTRACT_LOCAL_VARIABLE","EXTRACT_METHOD"]}}
[6:42:03 PM] [Analyzer] [Info] <== {"id":"8763","result":{"assists":[]}}
[6:42:04 PM] [Analyzer] [Info] <== {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
[6:42:04 PM] [Analyzer] [Info] <== {"event":"analysis.errors","params":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","errors":[{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":24506,"length":3,"startLine":414,"startColumn":39},"message":"Undefined name 'Tex'.","correction":"Try correcting the name to one that is defined, or defining the name.","code":"undefined_identifier","url":"https://dart.dev/tools/diagnostic-messages#undefined_identifier","hasFix":true}]}}
[6:42:04 PM] [Analyzer] [Info] <== {"event":"analysis.occurrences","params":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","occurrences":[{"element":{"kind":"CLASS","name":"IntroductionSeeds","location":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":441,"length":17,"startLine":9,"startColumn":7},"flags":0},"offsets":[441,618],"length":17},{"element":{"kind":"CLASS","name":"StatefulWidget","location":{"file":"C:\\src\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","offset":38431,"length":14,"startLine":896,"startColumn":16},"flags":1},"offsets":[467],"length":14},{"element":{"kind":"TOP_LEVEL_VARIABLE","name":"override","location":{"file":"C:\\src\\flutter\\bin\\cache\\pkg\\sky_engine\\lib\\core\\annotations.dart","offset":4627,"length":8,"startLine":114,"startColumn":14},"flags":10,"returnType":"Object"},"offsets":[488,799,1018,30554],"length":8},{"element":{"kind":"CLASS","name":"_IntroductionSeedsState","location":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":580,"length":23,"startLine":14,"startColumn":7},"flags":16},"offsets":[500,541,580],"length":23},{"element":{"kind":"METHOD","name":"createState","location":{"file":"D:\\Work\\Flutter\\addfaith\\lib\\introduction_screens\\introduction_seeds.dart","offset":524,"length":11,"startLine":11,"startColumn":27},"flags":0,"parameters":"()","returnType":"_IntroductionSeedsState"},"offsets":[524],"length":11},{"element":{"kind":"CLASS","name":"State","location":{"file":"C:\\src\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","offset":46318,"length":5,"startLine":1040,"startColumn":16},"flags":1,"typeParameters":"<T extends StatefulWidget*>"},"offsets":[612],"length":5},{"element":{"kind":"MIXIN","name":"SingleTickerProviderStateMixin","location":{"file":"C:\\src\\flutter\\packages\\flutter\\lib\\src\\widgets\\ticker_provider.dart","offset":3949,"length":30,"startLine":113,"…

I apologize if I'm doing something wrong and wanted to get advice on either how to fix that or where to refer for help.

  • Dart SDK version: 2.10.4 (stable) (Wed Nov 11 13:35:58 2020 +0100) on "windows_x64"
  • Windows 10 Education x64
  • VS Code
P2 analyzer-server area-analyzer

All 3 comments

I also have the same issue, Reloading window solves the issue. But the debugging stops and after a while it happens again. This happens in both Android studio as well as VS code. And I wonder this issue is still not posted before.

Same here.

No sure if it's connected but since it started around the same time: "hot reloading" freezes frequently now and only terminating the run process seems to help. Super annoying.

Any updates guys?

Was this page helpful?
0 / 5 - 0 ratings