thenWithExtract<R2> method

Future<R2?> thenWithExtract<R2>(
  1. Future<Response> nextRequest(
    1. M extracted,
    2. Response<R> prevResponse
    ),
  2. R2? finalExtractor(
    1. Response response
    )
)

继续链式调用,传递提取的对象和响应,并提取最终结果

注意:如果第一步使用了 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);
}