安装 dart
# 设置 brew 源
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# 安装
brew install dart-sdk
# 查看版本
dart --version
# 查看安装目录
arch -arm64 brew info dart-sdk
安装
项目
# 创建项目
dart create -t web web_app
<h2>A Simple To-Do List</h2>
<p>Things to do:</p>
<ul id="todolist">
</ul>
import 'dart:html';
Iterable<String> thingsTodo() sync* {
const actions = ['Walk', 'Wash', 'Feed'];
const pets = ['cats', 'dogs'];
for (final action in actions) {
for (final pet in pets) {
if (pet != 'cats' || action == 'Feed') {
yield '$action the $pet';
}
}
}
}
void addTodoItem(String item) {
final listElement = LIElement()..text = item;
todoList.children.add(listElement);
}
final UListElement todoList = querySelector('#todolist') as UListElement;
void main() {
thingsTodo().forEach(addTodoItem);
}
启动项目