rawRows method
Calls any NEIS service and returns its rows.
Entries of params with a null value are dropped. Pages are read until
the service runs out of rows or maxPages pages have been read, and an
empty list comes back when the query matches nothing.
NEIS paging needs care: list_total_count can be larger than the number
of rows a service actually returns, and some services answer a page
beyond the last one by repeating the first page instead of an empty list.
Paging therefore stops on a short page or a repeated page, so rows are
never duplicated.
Without an apiKey there is no paging to follow: NEIS answers every page with the same first 5 rows, so a keyless call returns 5 rows at most and stops after one request.
Implementation
Future<List<Map<String, Object?>>> rawRows(
String service,
Map<String, Object?> params, {
int? rows,
int maxPages = 5,
}) async {
final size = rows ?? pageSize;
final collected = <Map<String, Object?>>[];
Map<String, Object?>? firstRowOfPreviousPage;
for (var page = 1; page <= maxPages; page++) {
final result = await _request(service, params, page: page, size: size);
if (result.rows.isEmpty) break;
if (_sameRow(firstRowOfPreviousPage, result.rows.first)) break;
collected.addAll(result.rows);
firstRowOfPreviousPage = result.rows.first;
// A page shorter than requested is the last one, whatever the reported
// total says.
if (result.rows.length < size) break;
if (collected.length >= result.total) break;
}
return collected;
}