File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # 异步
2+
3+ 同步写法:
4+
5+ ``` dart
6+ // This example uses the Google Books API to search
7+ // for books about HTTP. For details, see
8+ // https://developers.google.com/books/docs/overview
9+ final url = Uri.https(
10+ 'www.googleapis.com',
11+ '/books/v1/volumes',
12+ {'q': '{http}'},
13+ );
14+
15+ // Await the HTTP GET response
16+ // and print the response body.
17+ http.get(url).then((result)=>print(result.body));
18+ ```
19+
20+ 修改自[ DartPad提供的样例] ( https://dartpad.cn/?id=4a68e553746602d851ab3da6aeafc3dd ) 。
21+
22+ ## Flutter
23+
24+ https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
25+
26+ ``` dart
27+ Widget buildOutput(input){
28+ return FutureBuilder(
29+ // https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
30+ future: executor.execute(input),
31+ builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
32+ if (snapshot.connectionState == ConnectionState.done) {
33+ // 请求已结束
34+ if (snapshot.hasError) {
35+ // 请求失败,显示错误
36+ return Text("Error: ${snapshot.error}");
37+ } else {
38+ // 请求成功,显示数据
39+ return Text("${snapshot.data}");
40+ }
41+ } else {
42+ // 请求未结束,显示正在加载的状态
43+ return const Text('代码运行中...');
44+ }
45+ },
46+ );
47+ }
48+ ```
Original file line number Diff line number Diff line change 1+ # CORS策略解决方案
2+
3+ 本地调试时关闭Chrome的检查:
4+ - https://pub.dev/packages/flutter_cors
5+ - https://stackoverflow.com/questions/65630743/how-to-solve-flutter-web-api-cors-error-only-with-dart-code
6+
7+ 如果` fluttercors ` 不可用,运行
8+
9+ ``` shell
10+ export PATH=" $PATH " :" $HOME /.pub-cache/bin"
11+ ```
12+
13+ 把命令行工具的执行路径加入配置。
Original file line number Diff line number Diff line change 1+ # 版本
2+
3+ <!-- 需要找到官方文档验证 -->
4+
5+ > In Dart conventions the +1 is used when publishing a patch release where the first number in the version is 0.
6+
7+ https://stackoverflow.com/questions/53626418/what-does-plus-one-1-mean-in-darts-dependency-versioning
You can’t perform that action at this time.
0 commit comments