PageParamFn<TPageData, TPageParam> typedef Infinite queries

PageParamFn<TPageData, TPageParam> = TPageParam? Function(TPageData page, List<TPageData> pages, TPageParam pageParam, List<TPageParam> pageParams)

Where the next (or previous) page starts, or null when there is none.

Given the page at the end being extended (the last page for getNextPageParam, the first for getPreviousPageParam), all pages, the param that end page was fetched with, and all params. For an offset cursor, for example:

getNextPageParam: (page, pages, pageParam, pageParams) =>
    page.length < pageSize ? null : pageParam + page.length,

Returning null means "no more pages": hasNextPage (or hasPreviousPage) turns false and a page fetch in that direction fetches nothing. Because null has that meaning, a nullable TPageParam is a poor choice: a param that is itself null cannot be told apart from the end of the list. Use a non-nullable type such as int or String.

Implementation

typedef PageParamFn<TPageData, TPageParam> = TPageParam? Function(
  TPageData page,
  List<TPageData> pages,
  TPageParam pageParam,
  List<TPageParam> pageParams,
);