非同期
async和待ち
これらの2つのキーワードの使用は、2つのポイントを覚えておく必要があるだけです。
asyncメソッドのみがawaitキーワードを使用してメソッドを呼び出すことができます。他の非同期メソッドを呼び出す場合は、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}.');
}
}
大きな頭