baimWonk
baimWonk

Reputation: 841

VSCode Can't Find the PATH To the Flutter SDK

I just tried to execute Flutter: New Project, but it shows an error that could not find a flutter SDK. I've ensured to complete all of the requirements from the flutter doctor.

enter image description here

enter image description here

Is there any way to solve this problem?

Thanks.

Upvotes: 67

Views: 209306

Answers (27)

Indra As Lesmana
Indra As Lesmana

Reputation: 335

if you have setup export path, you terminal will be fine flutter doctor will be ok. sometime vscode not. to manually setup.

  1. go to vscode setting -> (command + ,) on mac
  2. type SDK, click SDK on Dart section.
  3. click on Edit in settings.json
  4. add or change value

"dart.flutterSdkPath"

:

sampe value if you using fvm

"dart.flutterSdkPath": "/Users/username/fvm/default/bin"

Upvotes: 2

Adnan
Adnan

Reputation: 1282

I'm using fvm and apparently I've deleted the version that I'm depending on. please check vscode's settings.json file and also the settings.json under the .vscode folder in your project, and see where dart.flutterSdkPath points at.

Upvotes: 0

claaaaassic
claaaaassic

Reputation: 1

In my MacOS M2, I modify .zprofile

sudo nano .zprofile

export PATH="$PATH:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"

Use Option+X > P > Enter to save change and leave nano.

Upvotes: 0

Bhikkhu Subhuti
Bhikkhu Subhuti

Reputation: 542

I had this problem for a long time. I noticed I had a .vscode directory. I deleted (moved somewhere else) and it worked fine after that. Probably a mismatch between my original linux vsc project which was copied to windows OS vsc. I hope this helps.

Upvotes: 0

Gerwyn
Gerwyn

Reputation: 1

Step 1: Press "Locate SDK"

Step 2: Select the folder "flutter" (Browse your files until you find it, it's the default name)

Step 3: Inside the default flutter folder, select the "Bin" folder.

Step 4: Things should work out at this point :)

P.S. This worked on VS Code Editor (Windows 11)

Upvotes: 0

cansu
cansu

Reputation: 1144

For Apple M2 and .zshrc bash profile :

In my case, my problem was the relative path.

I changed the environment variable

from :

export PATH="$PATH:./flutter/bin"

to :

export PATH="$PATH:$HOME/flutter/bin"

And all is fine.

Upvotes: 1

I had the same problem, the solution was:

take the folder where you have extracted your zip file (for example: C:\src\flutter\flutter) then put it in the environment variable path and restart vscode.

Upvotes: 0

kibria-miran
kibria-miran

Reputation: 11

if youknow where have you extracted your zip file of dart(Eg. at the time of extraction i setup the path C:\src\flutter) then in vs code goto c drive -src -flutter -bin -cache -(dart-sdk)

select this folder and your vs code will be adjusted.

Upvotes: 1

O Dev
O Dev

Reputation: 73

Windows After make sure right Flutter version is in your path: https://docs.flutter.dev/get-started/install/windows and you can run flutter doctor successfully

in VS Code you need to go to File->Preferences->Settings (or Ctrl+,) then search for dart.flutterSdkPath then click on "Edit in settings.json" make sure it is the right path there.

Upvotes: 3

Javier Lopez
Javier Lopez

Reputation: 1

Please refer to the Get Flutter SDK section and locate where you have installed your flutter\bin folder. In my case, I put the flutter bin in my Documents folder.

See the following image Flutter\bin location

Upvotes: 0

Greg Fay
Greg Fay

Reputation: 507

QUICK SOLUTION!: If on macOS, PLUS everything had been working flawlessly previously, and this happens all of a sudden, or periodically, here is what I eventually discovered...

If your mac restarted, either on its own due to a crash, freeze or overnight install of updates, and VS Code was running, it generally restores all your vscode instances, but with various environment-related errors such as this one. The reason is that you are not running in the context of a shell and you don't have access to those environment settings. See this article from the VS Code documentation.

THE SOLUTION?: Quit and restart VS code as you normally would. Others have mentioned this, but I thought it would be good to know why this happens so you aren't surprised next time.

Upvotes: 1

nani
nani

Reputation: 203

For me non of the answers helped. What helped was (on macOS) opening the .bash_profile file via

  • sudo nano .bash_profile
  • and change the path to where my Flutter was as this has changed. Or add this line export PATH="$PATH:/home/user/path/to/flutter/bin"

hope this helpes.

Upvotes: 0

Nana kTk
Nana kTk

Reputation: 261

For those who want to change their Flutter SDK path for the Dart & Flutter plugin

  1. Click on Manage Icon(on Mac)
  2. Click on Settings
  3. On the Settings page, Click on Dart & Flutter.
  4. Look for Dart: Sdk Path, click on Edit in settings.json
  5. Edit dart.flutterSdkPath to your VSCode Flutter path

Upvotes: 0

Paulo Ravaiano
Paulo Ravaiano

Reputation: 81

I would like to complete NoobN3rd information.

In VSCode Linux I used this steps:

  1. sudo nano /etc/environment

  2. Type your password

  3. I added 3 paths at the end of line:

    3.1 /"flutter instalation directory"/flutter/bin
    3.2 /"flutter instalation directory"/flutter/packages
    3.3 /"flutter instalation directory"/flutter/dev
    
  4. Save it and reboot your system

Look at my environment file to have an example:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/paulo/development/flutter/bin:/home/paulo/development/flutter/packages:/home/paulo/development/flutter/dev"

Upvotes: 2

Omar Sherif
Omar Sherif

Reputation: 649

Check your environment variables:

  • Look for the PATH if it exists append the full path to flutter\bin using ; as a separator from existing values.

  • If it does not exist, create a new user variable named PATH with the full path to flutter\bin as its value.

And check the installation guide

After doing this:

  1. Open VS Code.
  2. Press Ctrl + Shift + P.
  3. Then type flutter and select run flutter doctor it should be fixed now.
  4. Create a new project to make sure it's run.

Upvotes: 8

Aldan
Aldan

Reputation: 715

For Windows

  1. Open Visual Studio Code
  2. Click Locate SDK
  3. Find your flutter folder
  4. Click Save
  5. Re-open your Visual Studio Code
  6. Press Ctrl + Shift + P
  7. Type flutter and choose Flutter: New Application Project
  8. Type your project name (e.g: flutter_application_1)
  9. Select a folder to create the project in

If you want to change your flutter sdk location

  1. Go to Visual Studio Code > Manage > Setting (or with shortcut Ctrl
  2. Search dart
  3. Find [dart] configure setting to be overriden for [dart] language
  4. Click Edit in settings.json

You'll see :

{
    "dart.sdkPath": "C:\\tools\\dart-sdk",
    "dart.flutterSdkPath": "C:\\tools\\flutter",
    "[dart]": {
        "editor.tabSize": 2,
        "editor.insertSpaces": true,
        "editor.detectIndentation": false,
        "editor.suggest.insertMode": "replace"
    }
}

Replace dart.sdkPath and dart.flutterSdkPath with your new sdk location

Upvotes: 12

Niroshan Ratnayake
Niroshan Ratnayake

Reputation: 3801

If you have just installed the flutter extension, close all the vs code applications running and restart the vs code then it will work as expected.

In order to run a new flutter project,

Go to vs code-> View tab -> command pallette -> select Flutter -> 
give a name to the project ->give the path of the project 

Now you are good to go with flutter.

Upvotes: 1

Mahesh Jamdade
Mahesh Jamdade

Reputation: 20221

The thing is VSCode looks for .packages file in your Flutter project this file contains path to your Flutter SDK & some other metadata. You're getting this error because either the .packages file is missing or either the path to Flutter SDK in .packages file contains some discrepancies.

To resolve it, you can;

  1. Either edit the .packages file & set the path.
  2. Or if you already have a working Flutter project then a .packages must've been already created. Copy that file & paste it in the root directory of your project.
  3. Restart VSCode & run flutter pub get

This should resolve the issue.

Upvotes: 16

Jarmos
Jarmos

Reputation: 456

Installing Flutter on Linux is a breeze using snapd as is documented officially. But then trying to create a Flutter project by following the official steps as mentioned here - Test drive - Flutter will throw an error similar to the description provided in the question.

On a side note though, you don't have to bother adding Flutter to PATH if it was installed using snapd.

Rather, follow these steps:

flutter create <insert_app_folder_name>
cd <insert_app_folder_name>
code .

What it really does is:

  • The Flutter binary is called from within snapd & creates a project with a directory name you provide.
  • You can now cd into that specific directory.
  • Call VSCode in the current directory which opens a VSCode instance within the project directory.

Refer to the answer by @maheshmnj about the .package. This file was created by Flutter earlier if you followed the aforementioned steps.

Upvotes: 3

Saif Ullah
Saif Ullah

Reputation: 1

i was also facing this error, after putting the flutter sdk path at the End of the PATH variable(not in middle or start) it works fine for me

Upvotes: 0

Pranjal Gupta
Pranjal Gupta

Reputation: 591

I just got out of the same trouble, after numerous hit and trials trying to run flutter commands from vs code terminal the below set of steps got the things up for me.

In Ubuntu 18.04

  1. Grab the path of the directory where flutter was unpacked by you.Mine was in the Home directory for the root user. Location can be any of your choice.
  2. Go to the Home for your root user
  3. Un-hide all of the hidden files in this directory.
  4. Look for .bashrc file. Do not look for .profile file.
  5. Open .bashrc file using nano/vim/text editor which ever you like.
  6. Scroll to the bottom of the file and add this line -

export PATH="$PATH:pwd/flutter_linux/flutter/bin"

  1. Quit all instances of the vscode (if any) opened.
  2. Re-open and in the terminal type which flutter

Here - I had re-named the un-zipped folder name like "flutter_linux_v1.12.13+hotfix.9-stable" with "flutter_linux"

Hope this helps......

Upvotes: 0

ant_dev
ant_dev

Reputation: 769

If you installed Flutter extension please restart VS_CODE and try it again. I already had the same problem.

Upvotes: 36

fakefla
fakefla

Reputation: 186

I would like to add a complementary and alternative response to the Linux solutions given by NoobN3rd, Traufvihal and Paulo Ravaiano.

I'm using Manjaro and for some reason my Visual Studio Code was not picking up all the environment variables definition. I tried all the solutions and finally I realised the problem was not with the variables definition (my final solution contains them all in ~/.bashrc but it should work with /etc/environment as well) but on how Visual Studio Code was launched.

In case someone else is facing this problem, I noticed that running VS Code from the applications menu fails to link the environment variables for some reason. On the other hand, launching "code-oss" from the terminal does the trick and picks all my variables defined in my ~/.bashrc file.

Hope it helps!

Upvotes: 3

Traufvihal
Traufvihal

Reputation: 64

I was facing the same problem. I've initially followed all the steps provided by installation guide of Flutter and was able to run an existing project using flutter run command. So I've tried again repeating the very same steps of the installation guide and changed the path that I initially set like:

export PATH="$PATH:~/path/to/flutter/bin"

For one like:

export PATH="$PATH:/home/user/path/to/flutter/bin"

Then I run source ~/.bashrc and restarted Visual Code and worked! so I suppose that it was something related to ~ in the path.

Upvotes: 1

Casey Schneider
Casey Schneider

Reputation: 1002

On macOS this was solved by following these steps.

First find where you downloaded the flutter sdk (Can be downloaded from here). It should be in your downloads folder unless you selected somewhere else.

Next:

  1. Open up Terminal. Run the following command: sudo nano /etc/paths
  2. Enter your password, when prompted.
  3. Go to the bottom of the file, and enter the path you wish to add.
  4. Hit control-x to quit.
  5. Enter “Y” to save the modified buffer.

If the sdk is downloaded into your Downloads folder, your path to add should be /Users/yourusername/Downloads/flutter/bin

Lastly, quit and restart your terminal windows and VS Code. After restarting, both apps should recognize flutter and running flutter doctor should now work.

Upvotes: 92

NoobN3rd
NoobN3rd

Reputation: 1261

For Linux Users

For future visitors :)

I had the same problem, in my Terminal flutter doctor or in general flutter was recognized, but VSCode couldn't recognize my SDK location so flutter doctor for instance didn't work.

The first thing to do is to follow the steps in flutter documentation: Flutter Doc

If it didn't work, change the environment variables directly.

sudo nano /etc/environment

Now add the location of the bin folder of your flutter SDK, The folder that you downloaded from here.

For example, you extracted it here: /Home/User/Software

Add /Home/User/Software/flutter/bin to the PATH variable. Paths are separated by a colon(:)

After a few solutions I tried, this one worked.

Upvotes: 6

Danny Tuppeny
Danny Tuppeny

Reputation: 42333

This means the Flutter extension couldn't find the Flutter SDK automatically (eg. by looking in your PATH or a path configured with dart.flutterSdkPath). Clicking Locate SDK should let you browse to the SDK manually and record that location for the next time. If you see this again after restarting, that's definitely a bug in the Dart/Flutter extension, so please open an issue at https://github.com/Dart-Code/Dart-Code and include the output from clicking the Show Log button, as well as noting whether there's a dart.flutterSdkPath setting in your VS Code User Settings.

Upvotes: 1

Related Questions