ZdsInfiniteListView class
Wrapper around a ListView.builder with Zds styling and functions for fetching new items when the user scrolls to the bottom of the list.
- hasMore - Whether the list has more items that have not yet been retrieved.
- onLoadMore - Function to retrieve more data.
Some variables have changed default values compared to ZdsList / ListView.
- padding - Default value is EdgeInsets.zero.
The other parameters act the same way as the ones in ZdsList, which extends ListView.
This example is split into state and view code, and shows how the onLoadMore function works with an API call.
// In state
List items = await service.apiCall();
// In view
ZdsInfiniteListView(
itemBuilder: ((_, index) {
return ZdsListTileWrapper(
top: index == 0,
bottom: index == items.length - 1,
child: ZdsListTile(
title: Text(items[index]),
),
);
}),
itemCount: items.length,
hasMore: true,
onLoadMore: () async => items += await service.apiCall(),
)
See also:
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ZdsInfiniteListView
- Available extensions
Constructors
-
ZdsInfiniteListView({required IndexedWidgetBuilder itemBuilder, required int itemCount, Key? key, Key? childKey, bool reverse = false, Axis scrollDirection = Axis.vertical, ScrollController? controller, bool? primary, ScrollPhysics? physics, bool shrinkWrap = false, EdgeInsetsGeometry? padding = EdgeInsets.zero, double? cacheExtent, String? restorationId, bool addAutomaticKeepAlives = true, bool addRepaintBoundaries = true, bool addSemanticIndexes = true, DragStartBehavior dragStartBehavior = DragStartBehavior.start, ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, Clip clipBehavior = Clip.hardEdge, bool showEmpty = false, WidgetBuilder? loadingBuilder, Future<
void> onLoadMore()?, bool hasMore = false, bool compact = false}) -
Creates a ZdsInfiniteListView.
const
Properties
- addAutomaticKeepAlives → bool
-
AddAutomaticKeepAlives passed to ZdsList.builder.
final
- addRepaintBoundaries → bool
-
AddRepaintBoundaries passed to ZdsList.builder.
final
- addSemanticIndexes → bool
-
AddSemanticIndexes passed to ZdsList.builder.
See:
final
- cacheExtent → double?
-
The viewport has an area before and after the visible area to cache items
that are about to become visible when the user scrolls.
final
- childKey → Key?
-
Key passed to ZdsList.builder.
final
- clipBehavior → Clip
-
The content will be clipped (or not) according to this option.
final
- compact → bool
-
Whether the list items should be close together, or separated.
final
- controller → ScrollController?
-
ScrollController passed to ZdsList.builder.
final
- dragStartBehavior → DragStartBehavior
-
Determines the way that drag start behavior is handled.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasMore → bool
-
Whether the list has more items that have not yet been retrieved.
When true, onLoadMore is called once the user scrolls to the bottom of the list.
final
- itemBuilder → IndexedWidgetBuilder
-
Builds individual items in the list.
final
- itemCount → int
-
Length of all items in the list.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- keyboardDismissBehavior → ScrollViewKeyboardDismissBehavior
-
ScrollViewKeyboardDismissBehavior the defines how this ScrollView will
dismiss the keyboard automatically.
final
- loadingBuilder → WidgetBuilder?
-
Builds loading widget whilst data is being fetched.
final
-
onLoadMore
→ Future<
void> Function()? -
Callback function that awaits the retrieval of more data items.
Typically used for an API call.
final
- padding → EdgeInsetsGeometry?
-
Default value is EdgeInsets.zero.
final
- physics → ScrollPhysics?
-
ScrollPhysics passed to passed to ZdsList.builder.
final
- primary → bool?
-
Primary passed to ZdsList.builder.
final
- restorationId → String?
-
Restoration ID to save and restore the scroll offset of the scrollable.
final
- reverse → bool
-
True to set the list in reverse. Defaults to false.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollDirection → Axis
-
Direction of scroll. Defaults to Axis.vertical.
final
- showEmpty → bool
-
Whether to show an empty list with a divider if the
children
list is empty.final - shrinkWrap → bool
-
ShrinkWrap passed to ZdsList.builder.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → ZdsInfiniteListViewState -
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.
override
-
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}) → 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