FeelRightz
FeelRightz

Reputation: 2979

vscode not select correct dart sdk

I have download different dart sdk and wish to switch sdk for different flutter project. In vscode I have add two downloaded dart sdk path into settings, and use Ctrl+Shift+P to change dart sdk location path, I selected Dart SDK 2.7.0 but vscode keep pointing back to the old dart sdk location (image below with Current setting)

enter image description here

Upvotes: 1

Views: 1725

Answers (2)

FeelRightz
FeelRightz

Reputation: 2979

Found a solution, inside root project folder create .vscode folder if don't have.

Next create settings.json if don't have. Paste the json below to overwrite current project sdk path. Remember to replace to your own sdk path

{
   "dart.flutterSdkPath": "C:\\flutter_1.22.6",
   "dart.sdkPath": "C:\\dart\\dart-sdk_2.7.0"
}

No need to change sdk path by using Ctrl+Shift+P each time.

Tip here, if facing any pub cache issue while building, just flutter clean and flutter pub get again

Upvotes: 2

Piyush Kumar
Piyush Kumar

Reputation: 482

You can try this, and create a launch.json, by going to Run in VScode menu, then Add Configurations,

Add the following, mind you, your project's directories.

    {
    "configurations": [
        {
            "program": "lib/main.dart",
            "name": "YOUR APP NAME",
            "cwd": "/home/u/Projects/fireflutter/live-projects/YOUR_PROJECT_FOLDER/",
            "type": "dart",
            "request": "launch",
            "flutterMode": "debug",
            "args": [
                // "--web-port",
                // "8080",
                // "--no-sound-null-safety",
                // pass your arguments here, whatever you would type 
                //in the terminal when you would use i.e 
                //flutter run --no-sound-null-safety[I love null safety by the way, 
                //but this is a common problem for people who still want to opt out of it.
            ],
        }
    ],
    "dart.flutterSdkPath": "/home/u/Downloads/sdks/flutter",
    "dart.sdkPath": "/home/u/Downloads/sdks/flutter/bin/dart",
}

Upvotes: -1

Related Questions