简体   繁体   English

如何在 VSCode 上更改我的 dart-sdk

[英]How can i change my dart-sdk on VSCode

i have been using flutter recently and i really wanted to use Jaguar for my project.我最近一直在使用 flutter,我真的很想在我的项目中使用 Jaguar。 But here is the catch, the flutter sdk brought dart with version 2.0.0-dev-58.0 but jaguar said they need dart sdk with version 2.0.0-dev-65.0但这里有一个问题,flutter sdk 带来了 2.0.0-dev-58.0 版本的 dart,但捷豹说他们需要 2.0.0-dev-65.0 版本的 dart sdk

Okay, so i get myself dart with sdk version of 2.1.0-dev.1.0, but my vscode can't seem to recognize that i have installed the sdk.好的,所以我让自己使用 2.1.0-dev.1.0 的 sdk 版本,但是我的 vscode 似乎无法识别我已经安装了 sdk。

Any ideas on how to change that?关于如何改变这种情况的任何想法?

The Dart Code plugin has a setting dart.sdkPath Dart Code插件有一个设置dart.sdkPath

The location of the Dart SDK to use for analyzing and executing code.用于分析和执行代码的 Dart SDK 的位置。 If blank, Dart Code will attempt to find it from the PATH environment variable.如果为空,Dart 代码将尝试从 PATH 环境变量中找到它。 When editing a Flutter project, the version of Dart included in the Flutter SDK is used in preference.在编辑 Flutter 项目时,优先使用 Flutter SDK 中包含的 Dart 版本。

There's also dart.sdkPaths which allows quick switching between alternatives.还有dart.sdkPaths允许在备选方案之间快速切换。

For Flutter projects, use dart.flutterSdkPath(s)对于 Flutter 项目,使用dart.flutterSdkPath(s)

It's quite easy if you use VSCode:如果您使用 VSCode,这很容易:

  1. Clone flutter repo to a new folder:将 flutter repo 克隆到新文件夹:
mkdir ~/flutter_dev
cd ~/flutter_dev
git clone https://github.com/flutter/flutter.git .
  1. Open your workspace preferences and update dart.flutterSdkPath setting:打开您的工作区首选项并更新dart.flutterSdkPath设置:
"settings": {
  "dart.flutterSdkPath": "/Users/youruser/flutter_dev"
}
  1. Restart VSCode and you're good to go.重新启动 VSCode,你就可以开始了。

See more info in Dart Code - Quickly Switching Between SDK VersionsDart 代码中查看更多信息- 在 SDK 版本之间快速切换

I want to add one more things to @Andrey, you can use FVM to install as much as you want versions and channels, it's easy to install and manage versions.我想再给@Andrey 添加一件事,您可以使用FVM安装任意数量的版本和频道,安装和管理版本很容易。 It hold all versions on your home directory, I think it's easier than managing with Git.它将所有版本保存在您的主目录中,我认为这比使用 Git 管理更容易。

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

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