使用 Flutter 向 API 服务器发送 POST 请求时出现以下错误。
没有为“FormData”类型定义“add”方法。([next_hour] lib\ui\edit_profile.dart:122 处的 undefined_method)
FormData formdata = new FormData();
Future <String> updateProfile() async{
newDob = DateFormat("y-MM-dd").format(_dateTime);
newMobile=_editMobileController.text;
print("dek: $newMobile");
newName=_editNameController.text;
String imagefileName = tmpFile != null ? tmpFile.path.split('/').last: '';
try{
if(imagefileName != ''){
formdata.add(
"image", new UploadFileInfo(tmpFile, imagefileName)
);
}
formdata.add(
"email", sEmail
);
formdata.add(
"current_password", sPass
);
formdata.add(
"new_password", sPass
);
formdata.add(
"dob", newDob
);
formdata.add(
"mobile", newMobile
);
formdata.add(
"name", newName
);
await dio.post(APIData.userProfileUpdate, data: formdata, options: Options(
method: 'POST',
headers: {
// ignore: deprecated_member_use
HttpHeaders.AUTHORIZATION: fullData,
}
)).then(
(response) {
setState(() {
isShowIndicator = false;
});
_profileUpdated(context);
}
)
.catchError((error) => print(error.toString()));
}
catch(e){
setState(() {
isShowIndicator = false;
});
print(e);
}
return null;
}