krequestT<T> function
请求数据,返回data数据为对象
void loading() async {
var data = await requestFutureT(
() => ApiRepository.get.getShopDetail("1"),
(json) => ShopDto.fromJson(json),
);
}
Implementation
Future<T?> krequestT<T>(Future<Response> Function() request,
T Function(dynamic json) fromJsonT) async {
try {
var json = await k_request(request);
var result = ResultDto<T>.fromJson(json, (json) => fromJsonT.call(json));
if (result.isSuccess()) {
return result.data;
} else {
throw NetException(code: result.errorCode, message: result.message);
}
} on Exception catch (ex) {
KHttpPlatform.get.throwHandler?.handleError(ex);
}
return null;
}