indexToLayoutOffset method

  1. @protected
double indexToLayoutOffset(
  1. double itemExtent,
  2. int index
)

The layout offset for the child with the given index.

This function uses the returned value of itemExtentBuilder or the itemExtent as an argument to avoid recomputing item size repeatedly during layout.

By default, places the children in order, without gaps, starting from layout offset zero.

Implementation

@protected
double indexToLayoutOffset(double itemExtent, int index) {
  if (itemExtentBuilder == null) {
    return itemExtent * index;
  } else {
    double offset = 0.0;
    for (int i = 0; i < index; i++) {
      offset += itemExtentBuilder!(i, _currentLayoutDimensions);
    }
    return offset;
  }
}