当前位置: 代码迷 >> 综合 >> Flutter Dio 报错is not a subtype of type ‘DioError‘
  详细解决方案

Flutter Dio 报错is not a subtype of type ‘DioError‘

热度:67   发布时间:2023-10-17 23:06:15.0
flutter 通过Dio调用接口报错 “is not a subtype of type 'DioError'”

拦截器中原代码如下:

@overrideonResponse(Response response) async{RequestOptions option = response.request;try {///一般只需要处理200的情况,300、400、500保留错误信息if (response.statusCode == 200 || response.statusCode == 201) {int code = response.data["code"];if (code == 0) {return new ResultData(response.data, true, ExceptionHandle.success,headers: response.headers);} else {return new ResultData(response.statusMessage, false, ExceptionHandle.success,headers: response.headers);}}} catch (e) {print(e.toString() + option.path);return new ResultData(ExceptionHandle.handleException(e).msg, false, response.statusCode,headers: response.headers);}return new ResultData(response.statusMessage, false, response.statusCode,headers: response.headers);
}

参考:https://blog.csdn.net/qq_34205937/article/details/108358553

修改后报错Flutter Dio 报错is not a subtype of type ‘DioError‘

后根据大佬的思路修改为:

@overrideonResponse(Response response) async{Map<String,dynamic> responseData = jsonDecode(response.toString());try {///一般只需要处理200的情况,300、400、500保留错误信息if (response.statusCode == 200 || response.statusCode == 201) {String code = responseData["code"];if (code=="0000") {return new ResultData(responseData["data"], true, ExceptionHandle.success,headers: response.headers);} else {return new ResultData(response.statusMessage, false, ExceptionHandle.success,headers: response.headers);}}} catch (e) {return new ResultData(ExceptionHandle.handleException(e).msg, false, response.statusCode,headers: response.headers);}return new ResultData(response.statusMessage, false, response.statusCode,headers: response.headers);}

解决了我所遇到的问题Flutter Dio 报错is not a subtype of type ‘DioError‘

  相关解决方案