getCollectionData<T> method

  1. @override
Future<List<T>> getCollectionData<T>({
  1. required String endpoint,
  2. JSON? queryParams,
  3. CancelToken? cancelToken,
  4. CachePolicy? cachePolicy,
  5. int? cacheAgeDays,
  6. bool requiresAuthToken = true,
  7. required T converter(
    1. 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);
  }
}