Dart
跳至導覽
跳至搜尋
Dart是一個程式語言。
安裝
wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg; echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list; sudo apt update; sudo apt install -y dart; sudo apt clean
範例
先初始化目錄:
dart create foo
然後進到foo/
裡面把Git環境先弄起來,並且把預設產生出來的初始環境先包進去:
cd foo; git init .; git add .; git commit -av -m 'Init by "dart create foo".'
然後就可以執行測試:
dart run
接著就可以開始修改了,這邊是先在pubspec.yaml
裡面加上http
:
dependencies:
http: ^1.2.1
然後就可以更新:
dart pub get
然後改bin/foo.dart
:
import 'package:http/http.dart' as http;
void main(List<String> arguments) async {
var url = Uri.https('www.google.com', 'robots.txt');
var response = await http.get(url);
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}
相關連結
外部連結
- 官方網站 (英文)
- Introduction to Dart (英文)
- Dart cheatsheet codelab (英文)