list method
GET /{resource}
Implementation
@override
Future<PaginatedRecords> list(
String resourceKey, {
int page = 1,
String? search,
String? sort,
String? direction,
}) async {
final resource = await _resource(resourceKey);
// Absent parameters are omitted rather than sent as null: the server
// rejects an unknown sort key with a 422, and an empty `search` would
// otherwise be a search for nothing.
final response = await _transport.get(
'$prefix/$resourceKey',
query: {
'page': '$page',
if (search != null && search.trim().isNotEmpty) 'search': search,
if (sort != null && sort.trim().isNotEmpty) 'sort': sort,
if (direction != null && direction.trim().isNotEmpty)
'direction': direction,
},
);
final rows = response['data'];
final meta = response['meta'];
return PaginatedRecords(
records: [
if (rows is List)
for (final row in rows)
if (row is Map<String, dynamic>)
ResourceRecord.fromJson(row, resource.recordKey),
],
meta: PageMeta.fromJson(meta is Map<String, dynamic> ? meta : const {}),
);
}