then<R> method

Future<Response<R>> then<R>(
  1. Future<Response<R>> nextRequest(
    1. Response<T> prevResponse
    )
)

链式调用下一个请求(支持传递前一个请求的 Response) 如果前一个请求失败,不会执行下一个请求

示例:

final result = await http.send(...)
  .then((prevResponse) => http.send(
    method: hm.post,
    path: '/next-step',
    data: {'token': prevResponse.extractField<String>('token')},
  ));

Implementation

Future<Response<R>> then<R>(
  Future<Response<R>> Function(Response<T> prevResponse) nextRequest,
) async {
  final prevResponse = await this;
  if (!prevResponse.isSuccess) {
    return prevResponse as Response<R>;
  }
  return await nextRequest(prevResponse);
}