InfiniteData<TPageData, TPageParam> class
final
Infinite queries
The data an infinite query holds: every page fetched so far, and the param each was fetched with.
An infinite query is an ordinary query whose data is an InfiniteData,
so everything the cache does — garbage collection, invalidation, filters,
getQueryData/setQueryData — works on it unchanged; only the fetch
differs, looping over pages instead of calling one function once.
The two lists are the same length and in the same order: pages[i] was
fetched with pageParams[i], and the constructor refuses anything else.
Treat the value as immutable. Every InfiniteData the library writes — a
fetch result, a structurally shared refetch, a copyWith — holds two
unmodifiable lists, so the value read back from the cache cannot be
grown behind the observers' backs: getInfiniteQueryData(key)!.pages .add(…) throws UnsupportedError. To change the pages, write a new
value with setQueryData (for example built with copyWith). The
constructor wraps nothing: a const [...] literal is already
unmodifiable, and a growable list handed in through initialData or
setQueryData stays the caller's own until the next fetch replaces it.
When every page is a list, flatten gives all items in order:
final data = client.getInfiniteQueryData<List<Post>, int>(
QueryKey(['feed']),
);
final posts = data?.flatten<Post>().toList() ?? const <Post>[];
- Annotations
-
- @immutable
Constructors
-
InfiniteData({required List<
TPageData> pages, required List<TPageParam> pageParams}) - Both lists at once; they must be the same length and in the same order.
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- isEmpty → bool
-
Whether no page is held —
pages.isEmpty. A value written by a fetch always holds at least one page; an empty one comes frominitialDataorsetQueryData.no setter -
pageParams
→ List<
TPageParam> -
The param each page was fetched with, index for index with pages.
final
-
pages
→ List<
TPageData> -
The pages in list order: FetchDirection.forward appends,
FetchDirection.backward prepends, and
maxPagesdrops from the far end.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
copyWith(
{List< TPageData> ? pages, List<TPageParam> ? pageParams}) → InfiniteData<TPageData, TPageParam> - This, with either list replaced. A replacement list is copied into an unmodifiable one; a list this instance already holds (not passed, or passed back as the very same object) is kept as it is, identity included — which is what lets structural sharing hand an unchanged list through unchanged.
-
flatten<
TItem> () → Iterable< TItem> - Every item of every page, for the common case where a page is a list.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
Equal when the runtime types are and both lists hold equal elements. The
runtime-type check keeps
==symmetric across type arguments, asQueryResult's and the structural-sharing walk's are.override