updatePositions method

void updatePositions({
  1. required Iterable<ItemPosition> positions,
  2. required void onValueChane({
    1. required int firstItem,
    2. required int lastItem,
    }),
})

Implementation

void updatePositions({
  required Iterable<ItemPosition> positions,
  required void Function({required int firstItem, required int lastItem})
      onValueChane,
}) async {
  if (positions.isNotEmpty) {
    _min = positions
        .where((ItemPosition position) => position.itemTrailingEdge > 0)
        .reduce((ItemPosition min, ItemPosition position) =>
            position.itemTrailingEdge < min.itemTrailingEdge ? position : min)
        .index;

    _max = positions
        .where((ItemPosition position) => position.itemLeadingEdge < 1)
        .reduce((ItemPosition max, ItemPosition position) =>
            position.itemLeadingEdge > max.itemLeadingEdge ? position : max)
        .index;
  }
  valueListenable.value = min;
  onValueChane(firstItem: min, lastItem: max);
  notifyListeners();
}