GetSliverList class

A scrollable list of widgets arranged linearly.

The GetListView.builder constructor takes an IndexedWidgetBuilder, which builds the children on demand. This constructor is appropriate for list views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

To control the initial scroll offset of the scroll view, provide a controller with its ScrollController.initialScrollOffset property set.

By default, GetListView will automatically pad the list's scrollable extremities to avoid partial obstructions indicated by MediaQuery's padding. To avoid this behavior, override with a zero padding property.

Construction

While laying out the list, visible children's elements, states and render objects will be created lazily based on existing widgets

Destruction

When a child is scrolled out of view, the associated element subtree, states and render objects are destroyed. A new child at the same position in the list will be lazily recreated along with new elements, states and render objects when it is scrolled back.

Destruction mitigation

In order to preserve state as child elements are scrolled in and out of view, the following options are possible:

  • Moving the ownership of non-trivial UI-state-driving business logic out of the list child subtree. For instance, if a list contains posts with their number of upvotes coming from a cached network response, store the list of posts and upvote number in a data model outside the list. Let the list child UI subtree be easily recreate-able from the source-of-truth model object. Use StatefulWidgets in the child widget subtree to store instantaneous UI state only.

  • Letting KeepAlive be the root widget of the list child widget subtree that needs to be preserved. The KeepAlive widget marks the child subtree's top render object child for keepalive. When the associated top render object is scrolled out of view, the list keeps the child's render object (and by extension, its associated elements and states) in a cache list instead of destroying them. When scrolled back into view, the render object is repainted as-is (if it wasn't marked dirty in the interim).

    This only works if addAutomaticKeepAlives and addRepaintBoundaries are false since those parameters cause the GetListView to wrap each child widget subtree with other widgets.

  • Using AutomaticKeepAlive widgets (inserted by default when addAutomaticKeepAlives is true). AutomaticKeepAlive allows descendant widgets to control whether the subtree is actually kept alive or not. This behavior is in contrast with KeepAlive, which will unconditionally keep the subtree alive.

    As an example, the EditableText widget signals its list child element subtree to stay alive while its text field has input focus. If it doesn't have focus and no other descendants signaled for keepalive via a KeepAliveNotification, the list child element subtree will be destroyed when scrolled away.

    AutomaticKeepAlive descendants typically signal it to be kept alive by using the AutomaticKeepAliveClientMixin, then implementing the AutomaticKeepAliveClientMixin.wantKeepAlive getter and calling AutomaticKeepAliveClientMixin.updateKeepAlive.

The key, scrollDirection, reverse, controller, primary, physics, and shrinkWrap properties on GetListView map directly to the identically named properties on CustomScrollView.

The padding property corresponds to having a SliverPadding in the CustomScrollView.slivers property instead of the list itself, and having the SliverList instead be a child of the SliverPadding.

Inheritance
Available Extensions

Constructors

GetSliverList({List<Widget> children = const [], EdgeInsetsGeometry? padding, double? itemExtent, Widget? prototypeItem, bool addAutomaticKeepAlives = true, bool addRepaintBoundaries = true, bool addSemanticIndexes = true, Axis scrollDirection = Axis.vertical, Key? key})
Creates a scrollable, linear array of widgets from an explicit List.
const
GetSliverList.builder({required GetItemBuilder itemBuilder, List? items, IndexedWidgetBuilder? dividerBuilder, WidgetBuilder? edgeDividerBuilder, WidgetBuilder? headerBuilder, WidgetBuilder? footerBuilder, GetSectionBuilder? sectionBuilder, GetSection? section, int? itemCount, DividerStyle? divider, DividerStyle edgeDivider = DividerStyle.full, EdgeInsetsGeometry? padding, bool addAutomaticKeepAlives = true, bool addRepaintBoundaries = true, bool addSemanticIndexes = true, Axis scrollDirection = Axis.vertical, Key? key})
Creates a fixed-length scrollable linear array of list "items" separated by list item "separators".
const

Properties

addAutomaticKeepAlives bool
final
addRepaintBoundaries bool
final
addSemanticIndexes bool
final
children List<Widget>?
final
divider DividerStyle?
final
dividerBuilder IndexedWidgetBuilder?
final
edgeDivider DividerStyle
final
edgeDividerBuilder WidgetBuilder?
final
footerBuilder WidgetBuilder?
final
hashCode int
The hash code for this object.
no setterinherited
headerBuilder WidgetBuilder?
final
itemBuilder GetItemBuilder?
final
itemCount int
final
itemExtent double?
If non-null, forces the children to have the given extent in the scroll direction.
final
items List?
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
padding EdgeInsetsGeometry?
The amount of space by which to inset the children.
final
prototypeItem Widget?
If non-null, forces the children to have the same extent as the given widget in the scroll direction.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollDirection Axis
final
section GetSection?
final
sectionBuilder GetSectionBuilder?
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
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}) 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