scrollToIndexIfNotVisible method

Future<void> scrollToIndexIfNotVisible(
  1. int index,
  2. double itemHeight, {
  3. Duration duration = const Duration(milliseconds: 300),
  4. Curve curve = Curves.easeInOut,
})

Scrolls to the given index only if the item is not visible already.

index is the target index of the item. itemHeight is the height of a single item.

Implementation

Future<void> scrollToIndexIfNotVisible(
  int index,
  double itemHeight, {
  Duration duration = const Duration(milliseconds: 300),
  Curve curve = Curves.easeInOut,
}) {
  if (!isItemVisible(index, itemHeight)) {
    return scrollToIndex(index, itemHeight, duration: duration, curve: curve);
  }
  return Future.value();
}