很久没更新dio了,编译时出现以下错误
../../../dev/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-2.2.2/lib/src/dio_http_headers.dart:55:8: Error: The method 'DioHttpHeaders.add' has fewer named arguments than those of overridden method 'HttpHeaders.add'. void add(String name, value) { ^ org-dartlang-sdk:///third_party/dart/sdk/lib/_http/http.dart:698:8: Context: This is the overridden method ('add'). void add(String name, Object value, ^ ../../../dev/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-2.2.2/lib/src/dio_http_headers.dart:70:8: Error: The method 'DioHttpHeaders.set' has fewer named arguments than those of overridden method 'HttpHeaders.set'. void set(String name, Object value) { ^ org-dartlang-sdk:///third_party/dart/sdk/lib/_http/http.dart:707:8: Context: This is the overridden method ('set'). void set(String name, Object value, ^ FAILURE: Build failed with an exception.
显示的错误是dio有问题,当前用的版本是2.1.12。
去dio的官网发现是版本问题,更新到最新的3.0重新编译即可,同时注意代码兼容性,从2.0升级到3.0很多api有了重大变化了,从2.0升级到3.0指南。
# dio: ^2.1.12 dio: ^3.0.10