InfiniteQueryController<TPageData, TPageParam, TData> class
Infinite queries
One infinite query, as a ValueListenable, with the paging operations and flags the sealed QueryResult does not carry.
The controller style for infinite queries, equal to context.infiniteQuery,
QueryMixin.watchInfiniteQuery and InfiniteQueryBuilder. As with
QueryController, you create it, listen to it and dispose it.
final feed = InfiniteQueryController(client, feedQuery());
// In a widget — a paging flag changing notifies too:
ListenableBuilder(
listenable: feed,
builder: (context, _) {
final posts = feed.value.dataOrNull?.flatten<Post>() ?? const <Post>[];
return Column(
children: [
for (final post in posts) Text(post.title),
if (feed.hasNextPage)
TextButton(
onPressed: feed.isFetchingNextPage ? null : feed.fetchNextPage,
child: const Text('Load more'),
),
],
);
},
);
// When done:
feed.dispose();
No type arguments at the call site: either options shape carries all
three, and inference reads them off it:
InfiniteQueryObserverOptions<List<Post>, int> makes an
InfiniteQueryController<List<Post>, int, InfiniteData<List<Post>, int>>.
- Inheritance
-
- Object
- ChangeNotifier
- QueryController<
InfiniteData< TPageData, TPageParam> , TData> - InfiniteQueryController
Constructors
-
InfiniteQueryController(QueryClient client, InfiniteQueryObserverOptionsBase<
TPageData, TPageParam, TData> options) -
Creates an InfiniteQueryObserver for
optionsonclient, with the same contract as QueryController.new: nothing is fetched until the first listener, and dispose destroys the observer.
Properties
- client → QueryClient
-
The client the observer runs on.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- hasNextPage → bool
-
Whether fetchNextPage has a page to fetch: the options'
getNextPageParam, given the pages held, returns a param. False before the first page is in, and false — not an error — once the paging function says there is no more.no setter - hasPreviousPage → bool
-
Whether fetchPreviousPage has a page to fetch: the options'
getPreviousPageParamreturns a param for the pages held. Always false when the options have none.no setter -
infiniteObserver
→ InfiniteQueryObserver<
TPageData, TPageParam, TData> -
The observer underneath, typed as the InfiniteQueryObserver it is —
observer with the paging half visible.
no setter
- isDisposed → bool
-
Whether dispose has run.
no setterinherited
- isFetchingNextPage → bool
-
Whether the fetch in flight is a fetchNextPage — the result's
isFetching, narrowed to the forward direction, so a refetch of the pages already held (isRefetching) does not count.no setter - isFetchingPreviousPage → bool
-
The backwards twin of isFetchingNextPage: the fetch in flight is a
fetchPreviousPage.
no setter
- isFetchNextPageError → bool
-
Whether the result's error came from a fetchNextPage — the result's
isError, narrowed to the forward direction. The pages already held are still there; a failed refetch of those is isRefetchError instead.no setter - isFetchPreviousPageError → bool
-
The backwards twin of isFetchNextPageError: the error came from a
fetchPreviousPage.
no setter
- isRefetchError → bool
-
Whether a refetch of the held pages failed, as opposed to a page fetch.
no setter
- isRefetching → bool
-
Whether the pages already held are being refetched, as opposed to a page
being added — the result's own
isRefetchingis true for both.no setter - observedState → Object?
-
The result and the paging flags a builder can show. Two fetches in
opposite directions leave the result equal, so without the flags the
reading styles would filter the change out.
no setteroverride
-
observer
→ QueryObserver<
InfiniteData< TPageData, TPageParam> , TData> -
The observer underneath, for the operations the controller does not
mirror, such as
currentQuery.no setterinherited -
optimisticValue
→ QueryResult<
TData> -
The result the observer would report on subscribing right now. Reported
by value while nobody listens; see there.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
value
→ QueryResult<
TData> -
The current result.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object.
inherited
-
fetchNextPage(
{bool cancelRefetch = true}) → Future< QueryResult< TData> > - Fetches the page after the ones already held.
-
fetchPreviousPage(
{bool cancelRefetch = true}) → Future< QueryResult< TData> > - Fetches the page before the ones already held.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
refetch(
{bool cancelRefetch = true}) → Future< QueryResult< TData> > -
Refetches, completing with the result the refetch produced.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
setInfiniteOptions(
InfiniteQueryObserverOptionsBase< TPageData, TPageParam, TData> options) → void - Replaces the options, paging half included. See QueryController.setOptions on why this does not notify, and why nothing is kept when the observer refuses.
-
setOptions(
QueryObserverOptionsBase< InfiniteData< options) → voidTPageData, TPageParam> , TData> -
Accepts any options that carry the paging behaviour — what
setInfiniteOptions and the core's own conversions produce — and
forwards them to the observer, exactly as
InfiniteQueryObserver.setOptionsdoes. Plain observer options have no paging half; applying them would silently drop it, so they are refused with an UnsupportedError in every build mode (anassertwould have made that a silent no-op in release). Nothing is kept when the observer refuses.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited