getMinChildIndexForScrollOffset method

  1. @protected
int getMinChildIndexForScrollOffset(
  1. double scrollOffset,
  2. double itemExtent
)

The minimum child index that is visible at the given scroll offset.

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

By default, returns a value consistent with the children being placed in order, without gaps, starting from layout offset zero.

Implementation

@protected
int getMinChildIndexForScrollOffset(double scrollOffset, double itemExtent) {
  if (itemExtentBuilder == null) {
    if (itemExtent > 0.0) {
      final double actual = scrollOffset / itemExtent;
      final int round = actual.round();
      if ((actual * itemExtent - round * itemExtent).abs() < precisionErrorTolerance) {
        return round;
      }
      return actual.floor();
    }
    return 0;
  } else {
    return _getChildIndexForScrollOffset(scrollOffset, itemExtentBuilder!);
  }
}