简体   繁体   English

vscode 不是 select 正确 dart sdk

[英]vscode not select correct dart sdk

I have download different dart sdk and wish to switch sdk for different flutter project.我已经下载了不同的 dart sdk 并希望为不同的 flutter 项目切换 sdk。 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 ) 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

在此处输入图像描述

Found a solution, inside root project folder create .vscode folder if don't have.找到了解决方案,如果没有,则在根项目文件夹中创建.vscode文件夹。

Next create settings.json if don't have.接下来创建settings.json如果没有。 Paste the json below to overwrite current project sdk path.粘贴下面的 json 以覆盖当前项目 sdk 路径。 Remember to replace to your own sdk path记得替换成自己的sdk路径

{
   "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.无需每次使用Ctrl + Shift + P更改 sdk 路径。

Tip here, if facing any pub cache issue while building, just flutter clean and flutter pub get again在这里提示,如果在构建时遇到任何 pub 缓存问题,只需flutter cleanflutter pub get

You can try this, and create a launch.json, by going to Run in VScode menu, then Add Configurations,你可以试试这个,并创建一个launch.json,通过在VScode菜单中运行,然后添加配置,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM