- override
Returns the estimated total height of the children, in pixels.
If there's an infinite number of children, this should return
double.INFINITY
.
The provided values can be used to estimate the total extent.
The firstIndex
and lastIndex
values give the integers that were passed
to buildItem
to build the respective widgets.
The minOffset
is the offset of the widget with index 0. Unless the
firstIndex
is 0, the minOffset
is only itself an estimate.
The firstStartOffset
is the offset of the widget with firstIndex
, in
the same coordinate space as minOffset
.
The lastEndOffset
is the offset of the widget that would be after
lastIndex
, in the same coordinate space as minOffset
. (In other words,
it's the offset to the end of the lastIndex
widget.)
A simple algorithm for this function, which works well when there are many children, the exact child count is known, and the children near the top of the list are more or less representative of the length of the other children, is the following:
// childCount is the number of children
return (lastEndOffset - minOffset) * childCount / (lastIndex + 1);
Source
@override double estimateTotalExtent(int firstIndex, int lastIndex, double minOffset, double firstStartOffset, double lastEndOffset) { final int childCount = children.length; if (childCount == 0) return 0.0; return (lastEndOffset - minOffset) * childCount / (lastIndex + 1); }