无法捕获 dioerror [dioerrortype.response]:http 状态错误 [statusCode]

Unable to catch dioerror [dioerrortype.response]: http status error [statusCode]

dioerror [dioerrortype.response]: http 状态错误 [statusCode]

这是 Headers 部分:

Headers("Authorization": "token", 
        "Content-Type" : "multipart/form-data", 
        "Accept" : "application/json")

这是数据部分:

    try {
      FormData data = FormData.fromMap({
        "username": userName.toString(),
        "name": naMe.toString(),
        "birthday": birthDay.toString(),
        "about": aboutUser.toString(),
        "sender": sendUser.toString(),
        "mobile": userMobile.toString(),
        "avatar": _image != null
            ? await MultipartFile.fromFile(_image.path,
                filename: avatarName.toString())
            : Text('Invalid Avatar'),
      }); 
     }

这是 Dio request/response 部分:

try {
     Dio dio = Dio();
     dio.options.headers['Accept'] = "multipart/form-data";
     dio.options.headers['Authorization'] = "Bearer $token";
     dio.options.headers['Content-Type'] = "application/json";

     var response = await dio.post(url, data: data);
     final res = json.encode(response.data);
     print('$res');
     var responseCode = response.statusCode;
     print('$responseCode');
 }

问题已通过使用

编辑 catch 博客解决
On DioError catch (error) {
   var statusCode = error.response.statusCode;
   Print(statusCode);
}