thenWithExtract<R2> method
继续链式调用,传递提取的对象和响应,并提取最终结果
注意:如果第一步使用了 http.isLoading.send(),整个链路只显示一个加载提示
在链路结束时(成功或失败)自动关闭
Implementation
Future<R2?> thenWithExtract<R2>(
Future<Response<dynamic>> Function(M extracted, Response<R> prevResponse)
nextRequest,
R2? Function(Response<dynamic> response) finalExtractor,
) async {
if (!response.isSuccess) {
// 前一步失败,关闭加载提示
if (_hasChainLoading) {
HttpUtilSafeCall.closeChainLoading();
}
return null;
}
final nextResponse = await nextRequest(extracted, response);
if (!nextResponse.isSuccess) {
// 下一步失败,关闭加载提示
if (_hasChainLoading) {
HttpUtilSafeCall.closeChainLoading();
}
return null;
}
// 链路成功完成,关闭加载提示
if (_hasChainLoading) {
HttpUtilSafeCall.closeChainLoading();
}
return finalExtractor(nextResponse);
}