getCollectionData<T> method
Future<List<T> >
getCollectionData<T>({
- required String endpoint,
- JSON? queryParams,
- CancelToken? cancelToken,
- CachePolicy? cachePolicy,
- int? cacheAgeDays,
- bool requiresAuthToken = true,
- required T converter(
- JSON responseBody
override
Implementation
@override
Future<List<T>> getCollectionData<T>({
required String endpoint,
JSON? queryParams,
CancelToken? cancelToken,
CachePolicy? cachePolicy,
int? cacheAgeDays,
bool requiresAuthToken = true,
required T Function(JSON responseBody) converter,
}) async {
List<Object?> body;
try {
final ResponseModel<List<Object?>> data = await _dioService.get<List<Object?>>(
endpoint: endpoint,
cacheOptions: _dioService.globalCacheOptions?.copyWith(
policy: cachePolicy,
maxStale: cacheAgeDays != null
? Nullable(Duration(days: cacheAgeDays))
: null,
),
options: Options(
extra: <String, Object?>{
'requiresAuthToken': requiresAuthToken,
},
),
queryParams: queryParams,
cancelToken: cancelToken,
);
body = data.body;
} on Exception catch (ex) {
throw CustomException.fromDioException(ex);
}
try {
return body.map((Object? dataMap) => converter(dataMap! as JSON)).toList();
} on Exception catch (ex) {
throw CustomException.fromParsingException(ex);
}
}