thenWithUpdate<R2> method
继续链式调用,传递提取的对象和响应,更新对象并返回(最后一步) 等同于 await chainResult.thenWithUpdate(...)
注意:nextRequest 回调中的 http.send(...) 是作为参数执行的,不是链式调用的继续
thenWithUpdate 返回 M?,不能继续链式调用
示例:
final result = await http.isLoading
.send(...)
.extractModel<FileUploadResult>(FileUploadResult.fromConfigJson)
.thenWith((uploadResult) => http.uploadToUrlResponse(...))
.thenWithUpdate<String>(
// nextRequest: 执行下一个请求(作为回调参数,不是链式调用)
(uploadResult, uploadResponse) => http.send(
method: hm.post,
path: '/uploader/get-image-url',
data: {'image_key': uploadResult.imageKey},
),
// extractor: 从响应中提取数据
(response) => response.extractField<String>('image_url'),
// updater: 更新对象并返回
(uploadResult, imageUrl) => uploadResult.copyWith(imageUrl: imageUrl),
);
// result 是更新后的 FileUploadResult,不能继续链式调用
Implementation
Future<M?> thenWithUpdate<R2>(
Future<Response<dynamic>> Function(M extracted, Response<R> prevResponse)
nextRequest,
R2? Function(Response<dynamic> response) extractor,
M Function(M extracted, R2? extractedValue) updater,
) async {
final chainResult = await this;
return await chainResult.thenWithUpdate<R2>(
nextRequest,
extractor,
updater,
);
}