requestWithFuture<T> method

Future<BaseResp<T>> requestWithFuture<T>({
  1. required String path,
  2. required OnFromJson<T>? onFromJson,
  3. ReqType reqType = ReqType.get,
  4. Map<String, dynamic>? params,
  5. Options? options,
  6. Map<String, dynamic>? body,
  7. CancelToken? cancelToken,
  8. RespConfig? respConfig,
  9. CacheMode? cacheMode = CacheMode.ONLY_NETWORK,
  10. int? cacheTime,
  11. String? customCacheKey,
})

需要异步调用的网络请求

Implementation

Future<BaseResp<T>> requestWithFuture<T>({
  required String path,
  required OnFromJson<T>? onFromJson,
  ReqType reqType = ReqType.get,
  Map<String, dynamic>? params,
  Options? options,
  Map<String, dynamic>? body,
  CancelToken? cancelToken,
  RespConfig? respConfig,
  CacheMode? cacheMode = CacheMode.ONLY_NETWORK,
  int? cacheTime,
  String? customCacheKey,
}) async {
  try {
    Response<dynamic> response = await requestResponse(
        path: path,
        reqType: reqType,
        params: params,
        respConfig: respConfig,
        options: options,
        body: body,
        cancelToken: cancelToken,
        cacheMode: cacheMode,
        cacheTime: cacheTime,
        customCacheKey: customCacheKey);

    return _parseResponse(response, respConfig, onFromJson);
  } on Exception catch (e) {
    return BaseResp(false, error: CstException.buildException(e));
  } on Error catch (e) {
    return BaseResp(false, error: CstException.buildException(Exception(e)));
  }
}