John
John

Reputation: 215

Visual Studio Code: dart not found

I just started working with Flutter, and can run my Flutter apps in Android Studio. I want to try Visual Studio Code, but when I click my run button, I get this in my Output window:

[Running] dart 
"c:\MyStuff\Source\Flutter\hello_world\test\widget_test.dart"
'dart' is not recognized as an internal or external command,
operable program or batch file.

[Done] exited with code=1 in 0.199 seconds

My first thought was my Path environment variable, which I have mangled trying to get this to work. It looks like this:

%USERPROFILE%\AppData\Local\Microsoft\WindowsApps; c:\Flutter\bin; 
c:\temp\flutter; c:\windows\system32; 
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; 
C:\temp\Flutter\bin\cache\dart-sdk.old1\bin

My c:\temp\Flutter directory looks like this:

https://i.sstatic.net/584fj.jpg

(I include that because I am a bit lost, and hoping someone will spot something I've done wrong.)

Does anyone have any ideas what I am doing wrong? This seems like it should just be basic setup, but I have obviously screwed it up. :(

EDIT:

Thanks for the response! I actually did that first thing. Flutter doctor gives me this:

[flutter] flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 
10.0.16299.547], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK 
28.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter 
doctor --android-licenses
[√] Android Studio (version 3.1)
[!] VS Code, 64-bit edition (version 1.25.1)
[√] Connected devices (1 available)
! Doctor found issues in 2 categories.
exit code 0

I don't know how to run Flutter doctor with a parameter (-v) in VSCode's command palette. Maybe that would give me more information. It seems to allow me only "canned" commands there. Do you know how I can run Flutter doctor with the -v parameter?

Upvotes: 6

Views: 30957

Answers (6)

Mehedi Hasan Shifat
Mehedi Hasan Shifat

Reputation: 720

You just need to add the path in your VS Code setting. In settings.json set this up:

"dart.flutterSdkPath": "/home/jspw/Android/Sdk/flutter/bin/cache/dart-sdk/bin/"

/home/jspw/Android/Sdk/flutter/bin/cache/dart-sdk/bin/ is my dart-sdk path !

You have to restart the VS Code and Boom! It's working fine !

Upvotes: 3

AnT
AnT

Reputation: 891

I have the similar issue from using import 'dart:html';

Apparently, as this answer explains, dart:html only comes with the regular Dart SDK, not with the Dart SDK shipped with Flutter.

Upvotes: 0

MR NDOKIST
MR NDOKIST

Reputation: 1

Your pc has not a Dart SDK, You must install Dart sdk in your computer,the link https://dart.dev/get-dart

1: https://dart.dev/get-dart or download a zip file https://dart.dev/tools/sdk/archive, after decompressing, take the bin folder path and add it to system varriables environement in the path...

Upvotes: 0

Ravi Yadav
Ravi Yadav

Reputation: 2386

Add the path of your Dart sdk into user/system environment variables. Lets say my Flutter SDK path is :E:\Android\flutter\bin

Now my Dart path will be inside :E:\Android\flutter\bin\cache\dart-sdk\bin

So edit the PATH variable and add the value at the end after a semicolon: E:\Android\flutter\bin\cache\dart-sdk\bin;

and restart the system and open cmd from windows and just simply run dart.

After restart In VS code go to New Terminal and add the terminal as Powershell and run dart command.

Upvotes: 3

Taio
Taio

Reputation: 3734

First of all, just place the sdk in an easy to reach place. mine is in the compressed directory of my downloads folder, works best for me this way. After extracting it locate the flutter_console.bat file according to your screenshot it is right there in the directory shown by screenshot. Run the file. Then go to environment variables in User variables modify path, and remove the other flutter directories and that dart directory you have put. put the whole path of the flutter directory for example mine is C: Users/UserName/Downloads/Compressed/flutter_windows_v0.5.1-beta/flutter/bin restart computer for the path to be updated

After restart Go to vs code settings in the User Settings, add this line to it

"dart.flutterSdkPath": "C:\\Users\\UserName\\Downloads\\Compressed\\flutter_windows_v0.5.1-beta\\flutter\\bin",

note the backslashes in above This is pointing the editor to the location of the Sdk. Also go to extensions search or marketplace and install the dart and flutter plugins

Upvotes: 7

Hector
Hector

Reputation: 447

You might have to configure your editor and install the flutter extension in your VScode (Visual Studio) https://flutter.io/get-started/editor/#vscode

Upvotes: 0

Related Questions