SliverChildListDelegate class

A delegate that supplies children for slivers using an explicit list.

Many slivers lazily construct their box children to avoid creating more children than are visible through the Viewport. This delegate provides children using an explicit list, which is convenient but reduces the benefit of building children lazily.

In general building all the widgets in advance is not efficient. It is better to create a delegate that builds them on demand using SliverChildBuilderDelegate or by subclassing SliverChildDelegate directly.

This class is provided for the cases where either the list of children is known well in advance (ideally the children are themselves compile-time constants, for example), and therefore will not be built each time the delegate itself is created, or the list is small, such that it's likely always visible (and thus there is nothing to be gained by building it on demand). For example, the body of a dialog box might fit both of these conditions.

The widgets in the given children list are automatically wrapped in AutomaticKeepAlive widgets if addAutomaticKeepAlives is true (the default) and in RepaintBoundary widgets if addRepaintBoundaries is true (also the default).

Accessibility

The CustomScrollView requires that its semantic children are annotated using IndexedSemantics. This is done by default in the delegate with the addSemanticIndexes parameter set to true.

If multiple delegates are used in a single scroll view, then the indexes will not be correct by default. The semanticIndexOffset can be used to offset the semantic indexes of each delegate so that the indexes are monotonically increasing. For example, if a scroll view contains two delegates where the first has 10 children contributing semantics, then the second delegate should offset its children by 10.

In certain cases, only a subset of child widgets should be annotated with a semantic index. For example, in new ListView.separated() the separators do not have an index assocaited with them. This is done by providing a semanticIndexCallback which returns null for separators indexes and rounds the non-separator indexes down by half.

See SliverChildBuilderDelegate for sample code using semanticIndexOffset and semanticIndexCallback.

See also:

Inheritance

Constructors

SliverChildListDelegate(List<Widget> children, { bool addAutomaticKeepAlives: true, bool addRepaintBoundaries: true, bool addSemanticIndexes: true, SemanticIndexCallback semanticIndexCallback: _kDefaultSemanticIndexCallback, int semanticIndexOffset: 0 })
Creates a delegate that supplies children for slivers using the given list. [...]
const

Properties

addAutomaticKeepAlives bool
Whether to wrap each child in an AutomaticKeepAlive. [...]
final
addRepaintBoundaries bool
Whether to wrap each child in a RepaintBoundary. [...]
final
addSemanticIndexes bool
Whether to wrap each child in an IndexedSemantics. [...]
final
children List<Widget>
The widgets to display.
final
estimatedChildCount int
Returns an estimate of the number of children this delegate will build. [...]
read-only, override
semanticIndexCallback SemanticIndexCallback
A SemanticIndexCallback which is used when addSemanticIndexes is true. [...]
final
semanticIndexOffset int
An initial offset to add to the semantic indexes generated by this widget. [...]
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

build(BuildContext context, int index) Widget
Returns the child with the given index. [...]
override
shouldRebuild(covariant SliverChildListDelegate oldDelegate) bool
Called whenever a new instance of the child delegate class is provided to the sliver. [...]
override
debugFillDescription(List<String> description) → void
Add additional information to the given description for use by toString.
@mustCallSuper, @protected, inherited
didFinishLayout(int firstIndex, int lastIndex) → void
Called at the end of layout to indicate that layout is now complete. [...]
inherited
estimateMaxScrollOffset(int firstIndex, int lastIndex, double leadingScrollOffset, double trailingScrollOffset) double
Returns an estimate of the max scroll extent for all the children. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited