requestWithFuture<T> method
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,
需要异步调用的网络请求
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)));
}
}