「Dart」:修訂間差異
跳至導覽
跳至搜尋
(未顯示同一使用者於中間所作的 3 次修訂) | |||
第32行: | 第32行: | ||
dependencies: | dependencies: | ||
http: ^1.2.1 | http: ^1.2.1 | ||
</syntaxhighlight> | |||
然後就可以更新: | |||
<syntaxhighlight lang="bash"> | |||
dart pub get | |||
</syntaxhighlight> | </syntaxhighlight> | ||
第37行: | 第43行: | ||
<syntaxhighlight lang="dart"> | <syntaxhighlight lang="dart"> | ||
void main() { | import 'package:http/http.dart' as http; | ||
print(' | |||
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}'); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
第49行: | 第60行: | ||
* {{Official|https://dart.dev/}} {{en}} | * {{Official|https://dart.dev/}} {{en}} | ||
* [https://dart.dev/language Introduction to Dart] {{en}} | |||
* [https://dart.dev/codelabs/dart-cheatsheet Dart cheatsheet codelab] {{en}} | |||
[[Category:程式語言]] | [[Category:程式語言]] |
於 2024年3月13日 (三) 09:58 的最新修訂
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 (英文)