itemExtentBuilder property

ItemExtentBuilder? itemExtentBuilder
final

If non-null, forces the children to have the corresponding extent returned by the builder.

Specifying an itemExtentBuilder is more efficient than letting the children determine their own extent because the scrolling machinery can make use of the foreknowledge of the children's extent to save work, for example when the scroll position changes drastically.

This will be called multiple times during the layout phase of a frame to find the items that should be loaded by the lazy loading process.

Should return null if asked to build an item extent with a greater index than exists.

Unlike itemExtent or prototypeItem, this allows children to have different extents.

For ListView.separated, the index argument passed to the callback represents the interleaved child index, which includes both items and separators. Even indices correspond to the items, and odd indices correspond to the separators.

To map the interleaved child index to the semantic item index (for example, to look up the extent in a data list), divide it by 2 (index ~/ 2).

See also:

  • SliverVariedExtentList, the sliver used internally when this property is provided. It constrains its box children to have a specific given extent along the main axis.
  • The itemExtent property, which allows forcing the children's extent to a given value.
  • The prototypeItem property, which allows forcing the children's extent to be the same as the given widget.

Implementation

final ItemExtentBuilder? itemExtentBuilder;