- 原因:因为要使用最新版本的
Xcode
所以Mac
系统版本升级到了10.15.5
。后来发现去运行flutter
项目会报很多错误,就直接把flutter
版本更新到了1.17.5
,再次运行还是报错。报错如下如下。1.17.5
对于http
请求的dio
包 有最低版本需求dio: 3.0.0
起步,有些语法在1.17
环境下无法运行和打包,所以如果flutter sdk
升级到1.17
后dio
插件版本最低也得是3.0
以后。
Compiler message:
../../Documents/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-2.1.4/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:694:8: Context: This is the overridden method ('add').
void add(String name, Object value,
^
../../Documents/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-2.1.4/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:703:8: Context: This is the overridden method ('set').
void set(String name, Object value,
^
- 解决办法:
- 升级
dio
版本m把dio
插件版本设置为3.0.0
或者以后的版本
- 把flutter版本回退到1.17以前。(如果Mac系统没有升级到最新的估计可以)
dio: ^3.0.9
- 升级后报错,版本升级后有很多方法和类都有修改,只需要修改成现在的方法即可
Compiler message:
lib/common/dao/order_dao.dart:743:19: Error: Method not found: 'UploadFileInfo'.
"file": new UploadFileInfo(new File(path), name),
^^^^^^^^^^^^^^
lib/common/dao/order_dao.dart:747:30: Error: Method not found: 'FormData.from'.
'params': new FormData.from(paramData),
^^^^ lib/common/net/interceptors/header_interceptor.dart:15:12: Error: A value of type 'RequestOptions' can't be assigned to a variable of type 'Future<dynamic>'.
- 'RequestOptions' is from 'package:dio/src/options.dart' ('../../Documents/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-3.0.9/lib/src/options.dart').
- 'Future' is from 'dart:async'.
return options;
^ lib/common/net/interceptors/log_interceptor.dart:28:12: Error: A value of type 'Response<dynamic>' can't be assigned to a variable of type 'Future<dynamic>'.
- 'Response' is from 'package:dio/src/response.dart' ('../../Documents/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-3.0.9/lib/src/response.dart').
- 'Future' is from 'dart:async'.
return response; // continue
^ lib/common/net/interceptors/log_interceptor.dart:37:12: Error: A value of type 'DioError' can't be assigned to a variable of type 'Future<dynamic>'.
- 'DioError' is from 'package:dio/src/dio_error.dart' ('../../Documents/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-3.0.9/lib/src/dio_error.dart').
- 'Future' is from 'dart:async'.
return err;
^ lib/common/net/interceptors/response_interceptor.dart:15:60: Error: The getter 'primaryType' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'primaryType'.
if (option.contentType != null && option.contentType.primaryType == "text") {
^^^^^^^^^^^ lib/common/net/interceptors/response_interceptor.dart:23:18: Error: A value of type 'ResultData' can't be assigned to a variable of type 'Future<dynamic>'.
- 'ResultData' is from 'package:nurse_coming_app/common/net/result_data.dart' ('lib/common/net/result_data.dart').
- 'Future' is from 'dart:async'.
return new ResultData(response.data, false, response.statusCode, headers: response.headers);
修改内容
FormData.from修改为FormData.fromMap
UploadFileInfo(File(path), name,)修改为MultipartFile.fromFile(path, filename: name)
- option.contentType.primaryType
option.contentType.primaryType修改为option.contentType
options.contentType = ContentType.json;修改为options.contentType = Headers.jsonContentType;
- 报错:Error: A value of type 'RequestOptions' can't be assigned to a variable of type 'Future<dynamic>'.在参数后面新增async即可。
@override
onRequest(RequestOptions options) async{
///超时
options.connectTimeout = 15000;
return options;
}
网友评论