krequestList<T> function
请求数据,返回集合
void loading() async {
var data = await requestFutureList<ShopDto>(
() => ApiRepository.get.nearbyMaxsShop(1, 0, 0),
(json) => ShopDto.fromJson(json),
);
}
Implementation
Future<List<T>?> krequestList<T>(Future<Response> Function() request,
T Function(dynamic json) fromJsonT) async {
try {
var json = await k_request(request);
var result =
ResultListDto<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;
}