Stephen Stewart
Stephen Stewart

Reputation: 179

VSCode dart analyzer stopped recognizing flutter/dart code

I have been using VSCode for flutter development without issue, then today all of a sudden the dart analyzer is complaining that the majority of the classes are undefined, or targets do not exists.

Has anyone seen this before?

I have restarted VSCode, restarted computer, uninstalled flutter/dart plugins, ran flutter doctor with no issues...I am out of ideas.

VSCode Issues

Upvotes: 14

Views: 12475

Answers (8)

Belema
Belema

Reputation: 757

try uninstalling your flutter and dart extension on vs code and then reinstalled them

Upvotes: -1

Divyang Kuntar
Divyang Kuntar

Reputation: 1

My Dart sdk path is misplaced....so change it on vs code ... GO to settings search dart and then click on dart anaylzer path next step is change this path to flutter SDK folder if it is wrong.

"dart.flutterSdkPath": "D:\CLG\flutter",

Upvotes: 0

Alex van Winkel
Alex van Winkel

Reputation: 41

For me, de-installing then re-installing VS Code did the trick !

I came to that conclusion after talking to someone on the Dart/Flutter Extension server on Discord.

Got help on Discord

Upvotes: 0

siva
siva

Reputation: 21

I got this problem too then I reinstalled dart and flutter plugin from androod studio and it's fixed.

Upvotes: 1

Francois Snyman
Francois Snyman

Reputation: 31

The issue might be caused by VSCode struggling to find the Dart SDK installation path, even if it's in your Windows PATH.

To fix, just give the Dart extension an explicit reference to your SDK installation(s) using the extension settings ([Ctrl + ,], type 'Dart:') or by directly editing settings.json ([Ctrl + Shift + P], type 'settings.json', [Enter]).

If you have both Flutter and the full Dart SDK installed, add both listings:

"dart.sdkPaths": [
  "C:\\Program Files (x86)\\Dart\\dart-sdk\\bin",
  "C:\\Program Files (x86)\\Flutter\\bin\\cache\\dart-sdk\\bin",
],

If you have only one installed (most commonly just Flutter), you can just add that one:

"dart.sdkPath": "C:\\Program Files (x86)\\Flutter\\bin\\cache\\dart-sdk\\bin",

Bonus bit: The multiple-SDK settings are great (and in fact intended) when developing different projects requiring various SDK versions. I find this is especially useful when working on multiple projects over several months or even years, especially considering how rapidly and regularly both Dart and Flutter are changing and maturing at present.

Upvotes: 3

Stephen Stewart
Stephen Stewart

Reputation: 179

This was an issue with the VS Code "Laravel blade spacer" extension. Once I removed the add on, I no longer had the problem

Upvotes: 0

Abhijeet Dash
Abhijeet Dash

Reputation: 146

Another approach can be.. to delete the dart SDK (the cache folder under the bin dir of flutter SDK). And use the cmd as admin to re download the sdk, by running flutter doctor.

Upvotes: 1

Aditya Nigam
Aditya Nigam

Reputation: 999

Go to pubspec.yaml, right click and do Get Packages. It seems to work for me all the time.

Upvotes: 11

Related Questions