【发布时间】:2020-06-30 07:23:41
【问题描述】:
我已经为我的 Fluter 项目配置了 BLoC + Chopper 并且所有 API 工作正常至今。目前,正在集成File 上传API,我面临来自Chopper 方面的一些问题,我不知道它是什么以及如何解决。
@Post(path: "FILE_UPLOAD_URL")
@multipart
Future<Response<ProfileResponse>> uploadUserProfilePic(
@Header("Authorization") String token,
@PartFile('file') List<int> file,
);
API 调用:
await SharedPreferenceHelper.getToken().then(
(token) async {
final bytes = (await File(event.file.path).readAsBytes()).toList();
final file = http.MultipartFile.fromBytes('file', bytes);
profileResponse =
await Provider.of<ApiService>(context, listen: false)
.uploadUserProfilePic(token, bytes);
},
);
从这个方法和文件 (object_patch.dart) 中抛出 NoSuchMethodError 异常,
@patch
@pragma("vm:entry-point", "call")
dynamic noSuchMethod(Invocation invocation) {
// TODO(regis): Remove temp constructor identifier 'withInvocation'.
throw new NoSuchMethodError.withInvocation(this, invocation);
}
【问题讨论】: