本节目标

  • 配置 Dart 开发环境
  • 解决墙内问题

环境

  • MacOS
  • Dart SDK 2.0.0

下载 SDK

SDK 列表

archive
archive

下载 URL

1
https://storage.googleapis.com/dart-archive/channels/stable/release/2.0.0/sdk/dartsdk-macos-x64-release.zip

墙内请替换域名 storage.flutter-io.cn

替换后 URL

1
https://storage.flutter-io.cn/dart-archive/channels/stable/release/2.0.0/sdk/dartsdk-macos-x64-release.zip

解压到磁盘

磁盘位置 ~/Documents/sdk/dart-sdk

配置 VSCode IDE

下载链接

安装 Dart 插件

编写 HelloWord

  • 新建目录 dart-learn

  • 编写文件 hello.dart

1
2
3
void main() {
print('hello word!');
}

调试运行

配置文件 launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dart",
"program": "${file}",
"request": "launch",
"type": "dart"
}
]
}

配置命令行模式

设置环境变量

1
2
3
4
5
6
7
8
# 打开配置文件
vim ~/.bash_profile

# 尾部加入配置
export PATH=~/Documents/sdk/dart-sdk/bin:$PATH

# 重载配置文件
source ~/.bash_profile

测试

新开命令行窗口

1
2
dart --version
Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "macos_x64"

参考


© 猫哥

https://ducafecat.tech