MoInfiniteScrollSliver<T> class
A sliver variant of the infinite scroll list, designed to be placed inside a CustomScrollView.
Because it is a sliver, the parent CustomScrollView is responsible for providing pull-to-refresh behaviour (e.g. via a RefreshIndicator wrapping the CustomScrollView, or a CupertinoSliverRefreshControl as a sibling sliver).
Minimal usage
CustomScrollView(
slivers: [
SliverAppBar(title: Text('Posts')),
MoInfiniteScrollSliver<Post>(
fetcher: (page, limit) => api.getPosts(page: page, limit: limit),
itemBuilder: (context, post) => PostCard(post: post),
),
],
)
With pull-to-refresh controlled by the parent
final _controller = MoInfiniteScrollController<Post>();
RefreshIndicator(
onRefresh: () => _controller.refresh(fetcher, limit),
child: CustomScrollView(
slivers: [
MoInfiniteScrollSliver<Post>(
controller: _controller,
fetcher: fetcher,
itemBuilder: (context, post) => PostCard(post: post),
),
],
),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- MoInfiniteScrollSliver
Constructors
-
MoInfiniteScrollSliver({Key? key, required PageFetcher<
T> fetcher, required Widget itemBuilder(BuildContext context, T item), int limit = 20, int prefetchOffset = 3, MoInfiniteScrollController<T> ? controller, Widget? loadingPlaceholder, Widget? emptyPlaceholder, Widget? errorPlaceholder, Widget? loadingMoreIndicator, Widget separatorBuilder(BuildContext context, int index)?}) -
Creates a MoInfiniteScrollSliver.
const
Properties
-
controller
→ MoInfiniteScrollController<
T> ? -
Optional external controller. Expose this to allow the parent widget to
trigger refreshes from outside the sliver.
final
- emptyPlaceholder → Widget?
-
Widget shown when the list is empty after a successful fetch.
Defaults to DefaultEmptyPlaceholder.
final
- errorPlaceholder → Widget?
-
Widget shown when a fetch throws an error.
Defaults to DefaultErrorPlaceholder.
final
-
fetcher
→ PageFetcher<
T> -
Called whenever a new page is needed.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- itemBuilder → Widget Function(BuildContext context, T item)
-
Builds a single item widget.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- limit → int
-
Number of items to request per page. Passed directly to fetcher.
Defaults to 20.
final
- loadingMoreIndicator → Widget?
-
Optional widget displayed at the end of the list when more items are
being fetched (pagination loading indicator). If null, no indicator
is shown.
final
- loadingPlaceholder → Widget?
-
Widget shown while the very first page is loading.
Defaults to DefaultLoadingPlaceholder.
final
- prefetchOffset → int
-
How many items from the end should trigger a pre-fetch.
Defaults to 3.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- separatorBuilder → Widget Function(BuildContext context, int index)?
-
Optional separator builder, mirroring SliverList usage.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< MoInfiniteScrollSliver< T> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited