비동기
async 和 await
이 두 키워드를 사용하려면 다음 두 가지 사항 만 기억하면됩니다.
async 메서드 만 await 키워드를 사용하여 메서드를 호출 할 수 있습니다. 다른 async 메서드를 호출 할 경우 await 키워드를 사용해야합니다.
async는 메서드를 비동기 적으로 만드는 것입니다.
await는 비동기 메서드 실행이 완료 될 때까지 기다리는 것입니다.
일반 라이브러리
/** 使用 第三方 pub 包管理系统
*
* 1、从下面网址找到要用的库
* https://pub.dev/packages
* https://pub.flutter-io.cn/packages
* https://pub.dartlang.org/flutter/
*
*
* 2、创建一Tpubspec.yaml文件,内容如下
* name: XXX
* description: A new flutter module project.
* dependencies:
* http: ^0.12.0+2
* date_format: ^1.0.6
* 3、配置dependencies
* 4、运行put get 获取远程库
* 5、看文档引入库使用
*/
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;
void main(List<String> arguments) async {
// This example uses the Google Books API to search for books about http.
// https://developers.google.com/books/docs/overview
var url =
Uri.https('www.googleapis.com', '/books/v1/volumes', {'q': '{http}'});
// Await the http get response, then decode the json-formatted response.
var response = await http.get(url);
if (response.statusCode == 200) {
var jsonResponse = convert.jsonDecode(response.body);
var itemCount = jsonResponse['totalItems'];
print('Number of books about http: $itemCount.');
} else {
print('Request failed with status: ${response.statusCode}.');
}
}
큰 머리