13

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stephen Stewart
  • 169
  • 3
  • 8

7 Answers7

10

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

Aditya Nigam
  • 869
  • 2
  • 11
  • 21
3

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.

1

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.

Abhijeet Dash
  • 146
  • 1
  • 10
1

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

Asocia
  • 5,935
  • 2
  • 21
  • 46
siva
  • 21
  • 7
0

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

Stephen Stewart
  • 169
  • 3
  • 8
0

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

0

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",