list method

  1. @override
Future<PaginatedRecords> list(
  1. String resourceKey, {
  2. int page = 1,
  3. String? search,
  4. String? sort,
  5. String? direction,
  6. bool reorder = false,
  7. Map<String, Object?> filters = const {},
})
override

GET /{resource}

reorder: true switches to the full, unpaginated, reorder-ordered list — ?reorder=1 — and sort/direction are omitted from the request entirely, mirroring the server's own contract (P18): reorder mode discards the sort column outright, the same way Filament's own reorder-mode table does. search still applies in this mode.

filters (P24): name => String (single value) or List<String> (multiple). Encoded on the wire as INDEXED keys — filter[tags][0]=a&filter[tags][1]=b — never repeated ones (filter[tags][]=a&...). FilamentTransport.get hands the host a FLAT map, and the reference host stringifies every value (example/lib/http_filament_transport.dart), so a List<String> value would go out as the literal "[a, b]". Distinct indexed keys stay scalar strings — no change needed to the port or to any host — and PHP parses filter[tags][0]/filter[tags][1] into the same array filter[tags][] would have produced. The server accepts both forms; this client sends only the indexed one. Do not "simplify" this to repeated keys — that silently breaks multiple filters.

Implementation

@override
Future<PaginatedRecords> list(
  String resourceKey, {
  int page = 1,
  String? search,
  String? sort,
  String? direction,
  bool reorder = false,
  Map<String, Object?> filters = const {},
}) 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. `reorder: true` additionally omits
  // `sort`/`direction` outright — the server ignores them in that mode
  // anyway, but sending them would make this client the one exception to
  // the contract's "?reorder=1 sends no sort params".
  final response = await _read(
    '$prefix/$resourceKey',
    query: {
      'page': '$page',
      if (search != null && search.trim().isNotEmpty) 'search': search,
      if (reorder) 'reorder': '1',
      if (!reorder && sort != null && sort.trim().isNotEmpty) 'sort': sort,
      if (!reorder && direction != null && direction.trim().isNotEmpty)
        'direction': direction,
      ..._filterQuery(filters),
    },
  );

  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 {}),
  );
}