添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

VS Code-'dart' is not recognized as an internal or external command, operable program or batch file

Ask Question

I am trying to install flutter and run the basic flutter example on visual studio code . I used flutter doctor in the command line and installed all the missing requirements , now i try to run a basic program in flutter ,but in visual studio code output i get the following error

 [Running] dart "c:\fluttercode\mobile_test1\lib\main.dart"
'dart' is not recognized as an internal or external command,
operable program or batch file.
[Done] exited with code=1 in 64.965 seconds

I could find only one question similar to this in stack overflow , Visual Studio Code: dart not found they told to change environment variables ,i added the environment variables (however the name of the environment variables was not mentioned in the answer ) I checked the dart site in case they mentioned it ,but i couldn't find anything related to the name of the environment variable This is what i got from dart site

Windows: In Windows, setting your PATH and environment variables can be done by opening Control Panel and typing “Environment” and then clicking the “Edit the system environment variables” option. You’ll be presented with a list of environment variables including PATH where you can edit or add new ones.

Note: You should reboot your computer after making changes to PATH to ensure all processes (including explorer) are updated.

So i just did a guess and added an environment variable with the name FLUTTER_ROOT(cause i remember reading somewhere in one of the settings in VS Code for dart ,this name was used) and pointed it to my flutter bin directory

I restarted my PC and opened vs code and changed in VS Settings >user settings>dart and flutter>Dart:Env and updated my path

"files.autoSave": "afterDelay", "dart.flutterSdkPath": "C:\\src\\flutter\\bin"

But i get the same error

this is how my flutter bin folder looks like

Environment variables in PATH after installing Dart

what is your PATH env variable after reboot? does it really contain the folder where dart.exe is installed? – pskink May 12, 2019 at 7:29 I checked the PATH variable ,it didnt have the flutter path in it ,so i added C:\src\futter\bin to the PATH ,and restarted the PC .However this path does not have dart.exe . – krishna May 12, 2019 at 8:00 I installed dart on VSCode ,and before installing flutter files i did see a message saying dart is not required if you are building only mobile apps through flutter.But i just now installed dart through Chocolatey and trying to work things out – krishna May 12, 2019 at 8:06

You don't have to install the dart SDK if you already have the flutter SDK installed. When you specify the path of flutter, VSCode only recognizes the flutter commands and not the dart commands. What you should do is change the system environment variables (type env in the windows search bar) and add the dart sdk inside the PATH variable. The dart sdk is usually found inside /bin/cache/dart/bin. This worked for me, so give it a try

I had the same problem. Here is how I resolved it.

Download and extract dart sdk (I used the stable release) https://v1-dartlang-org.firebaseapp.com/install/archive

add the dart sdk bin folder to your path

after you have added it to your path run

flutter pub global activate webdev

now i can run

webdev serve

without error.

Installing flutter is not enough. You need to install the dart sdk.

Pre-req: Make sure you have Chocolatey installed on your machine.

  • Run "choco install dart-sdk" from an elevated prompt.
  • Restart vscode.
  • That did it for me.

    This is just a more descriptive answer but is similar to the above answers.

    Copy the file explorer paths for dart, flutter, and Pub (note the path for dart needs to specify the dart.exe file) and paste them into your user PATH variables (type 'env' in Windows search bar) like the following:

  • C:\Users\ [username] \Downloads\flutter_windows_3.3.10-stable\flutter\bin\cache\dart-sdk\bin

  • C:\Users\ [username] \AppData\Local\Pub\Cache\bin

  • C:\Users\ [username] \Downloads\flutter_windows_3.3.10-stable\flutter\packages\flutter

    Afterwards save everything and restart your computer before attempting any dart or flutter commands!

    I went to the dart website and searched for the dart sdk. i then chose the option to install dart using setup wizard. After running the executable file on my laptop it took some time to download all the files but once the setup was complete the error no longer occurred and i was able to run the code successfully.
    Downloading dart setup from dart website

    Installing using setup wizard

  •