asynchronous
async和await
The use of these two keywords only needs to remember two points:
Only the async method can use the await keyword to call the method. If you call other async methods, you must use the await keyword
async is to make a method asynchronous.
await is to wait for the completion of the asynchronous method execution.
Generic library
/** 使用 第三方 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}.');
}
}
Big head