getMinChildIndexForScrollOffset method

  1. @visibleForTesting
  2. @protected
int getMinChildIndexForScrollOffset(
  1. double scrollOffset,
  2. @Deprecated('The itemExtent is already available within the scope of this function. ' 'This feature was deprecated after v3.20.0-7.0.pre.') 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 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

@visibleForTesting
@protected
int getMinChildIndexForScrollOffset(
  double scrollOffset,
  @Deprecated(
    'The itemExtent is already available within the scope of this function. '
    'This feature was deprecated after v3.20.0-7.0.pre.'
  )
  double itemExtent,
) {
  if (itemExtentBuilder == null) {
    itemExtent = this.itemExtent!;
    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!);
  }
}