thenWith<R2, E> method
继续链式调用(中间步骤) 等同于 await chainResult.thenWith(...)
参数说明:
nextRequest: 下一个请求(必需)extractor: 从响应中提取数据(可选),如果提供,会提取数据用于更新对象updater: 更新对象(可选),如果提供,会用提取的数据更新对象
示例1:中间步骤,不更新对象
final chainResult = await http.isLoading
.send(...)
.extractModel<FileUploadResult>(FileUploadResult.fromConfigJson)
.thenWith((uploadResult) => http.uploadToUrlResponse(...));
示例2:中间步骤,更新对象并继续链式调用
final chainResult = await http.isLoading
.send(...)
.extractModel<FileUploadResult>(FileUploadResult.fromConfigJson)
.thenWith(
(uploadResult, prevResponse) => http.send(...),
extractor: (response) => response.extractField<String>('image_url'),
updater: (uploadResult, imageUrl) => uploadResult.copyWith(imageUrl: imageUrl),
)
.thenWith((updatedUploadResult, prevResponse) => http.send(...)); // 可以继续链式调用
Implementation
Future<ChainResult<M, R2>> thenWith<R2, E>(
Future<Response<R2>> Function(M extracted, Response<R> prevResponse)
nextRequest, {
E? Function(Response<R2> response)? extractor,
M Function(M extracted, E? extractedValue)? updater,
}) async {
final chainResult = await this;
return await chainResult.thenWith<R2, E>(
nextRequest,
extractor: extractor,
updater: updater,
);
}