安装与使用

第一个Dart程序

安装好Dart SDK后, 编写一个 test.dart 文件, 输入:

main() {
  print("Hello, World!");
}

执行 dart test.dart, 控制台输入 Hello, World!

包管理工具

pub 是 Dart 的包管理工具, 比如安装:

pub global activate webdev
pub global activate stagehand

Windows 注意将 C:\Users\quanzaiyu\AppData\Roaming\Pub\Cache\bin 添加到环境变量

开发 web 应用

# 安装相关工具
pub global activate webdev
pub global activate stagehand
# 创建web应用
mkdir quickstart
cd quickstart
stagehand web-simple
# 安装依赖
pub get
# 启动服务
$ webdev serve
[INFO] Building new asset graph completed, took 816ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 0ms
[INFO] Serving `web` on http://127.0.0.1:8080
[INFO] Running build completed, took 974ms
[INFO] Caching finalized dependency graph completed, took 83ms
[INFO] Succeeded after 1.1s with 11 outputs (1437 actions)
[INFO] ----------------------------------------------------------------------------------------------------------------

可以看到应用启动在 http://127.0.0.1:8080, 打开浏览器访问, 页面输出: Your Dart app is running.

MIT Licensed | Copyright © 2018-present 滇ICP备16006294号

Design by Quanzaiyu | Power by VuePress