我如何 post 用户的图像和其他配置文件数据使用 multipart with dio in flutter

How can i post user's image and other profile data using multipart with dio in flutter

我是 flutter 的新手,想了解如何在 flutter 中使用 Dio 发出多部分 post 请求。场景是在我的应用程序中,我希望允许用户使用多部分 post 请求提交 his/her 个人资料详细信息和个人资料图片。我正在尝试下面的代码。请在此代码中提供任何其他改进。

try{
  String filename = _image.path.split("/").last;
  FormData formData = new FormData.fromMap({

    "visitor_photo":  await MultipartFile.fromFile(_image.path,filename: filename, contentType: new MediaType('image','png')),
    "type": "image/png"
  });

  Response response =
      await dio.post(url,data: formData,options: Options(
        headers: {
          "accept": "*/*",
          "Authorization": "Bearer 0rwQmHeADz6g",
          "Content-Type" : "multipart/form-data"
        }
      ));
}catch(e){
  print(e);
}
Future<String> uploadImage(File file) async {
    String fileName = file.path.split('/').last;
    FormData formData = FormData.fromMap({
        "file":
            await MultipartFile.fromFile(file.path, filename:fileName),
    });
    response = await dio.post("/info", data: formData);
    return response.data['id'];
}