Dart:修订间差异
跳到导航
跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
无编辑摘要 |
(→外部連結) |
||
(未显示同一用户的9个中间版本) | |||
第5行: | 第5行: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
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 | 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 | ||
</syntaxhighlight> | |||
== 範例 == | |||
先初始化目錄: | |||
<syntaxhighlight lang="bash"> | |||
dart create foo | |||
</syntaxhighlight> | |||
然後進到<code>foo/</code>裡面把[[Git]]環境先弄起來,並且把預設產生出來的初始環境先包進去: | |||
<syntaxhighlight lang="bash"> | |||
cd foo; git init .; git add .; git commit -av -m 'Init by "dart create foo".' | |||
</syntaxhighlight> | |||
然後就可以執行測試: | |||
<syntaxhighlight lang="bash"> | |||
dart run | |||
</syntaxhighlight> | |||
接著就可以開始修改了,這邊是先在<code>pubspec.yaml</code>裡面加上<code>http</code>: | |||
<syntaxhighlight lang="yaml"> | |||
dependencies: | |||
http: ^1.2.1 | |||
</syntaxhighlight> | |||
然後就可以更新: | |||
<syntaxhighlight lang="bash"> | |||
dart pub get | |||
</syntaxhighlight> | |||
然後改<code>bin/foo.dart</code>: | |||
<syntaxhighlight lang="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}'); | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
第14行: | 第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 (英文)