onResponse<ResponseType, InnerType> method
ApiResponse<ResponseType, InnerType>
onResponse<ResponseType, InnerType>(
- ApiResponse<
ResponseType, InnerType> response
override
Intercepts the response and returns the modified response
Implementation
@override
ApiResponse<ResponseType, InnerType> onResponse<ResponseType, InnerType>(
ApiResponse<ResponseType, InnerType> response,
) {
final decoded = _tryDecodeJson(response.bodyString);
// ignore: deprecated_member_use_from_same_package
final nestedKey = response.request.nestedKey;
final hasEnvelope = nestedKey != null && nestedKey.isNotEmpty;
// Legacy: while nestedKey is set it scopes everything beneath it. Without
// it, dataKey and paginationKey are both absolute from the root.
final envelope = hasEnvelope
? _resolve(decoded, nestedKey, 'nestedKey')
: decoded;
Pagination? pagination;
if (response.request.hasPagination && paginationFactory != null) {
final source = hasEnvelope
? envelope
: _resolve(decoded, response.request.paginationKey, 'paginationKey');
if (source is Map<String, dynamic>) {
pagination = paginationFactory!(source);
}
}
final body = _decode<InnerType>(
_resolve(envelope, response.request.dataKey, 'dataKey'),
);
return response.copyWith(body: body, pagination: pagination);
}