scrollToIndex method

Future<bool> scrollToIndex(
  1. int index, {
  2. bool animate = true,
  3. Duration duration = const Duration(milliseconds: 300),
  4. Curve curve = Curves.easeInOut,
  5. double alignment = 0.0,
  6. EdgeInsets padding = EdgeInsets.zero,
  7. BuildContext? sliverContext,
  8. bool isFixedHeight = false,
})

Scrolls to make the item at index visible, using animation if animate is true.

This is a convenience method that calls either animateToIndex or jumpToIndex based on the animate parameter.

Example:

await cubit.scrollToIndex(10, animate: true);
cubit.scrollToIndex(0, animate: false);

Implementation

Future<bool> scrollToIndex(
  int index, {
  bool animate = true,
  Duration duration = const Duration(milliseconds: 300),
  Curve curve = Curves.easeInOut,
  double alignment = 0.0,
  EdgeInsets padding = EdgeInsets.zero,
  BuildContext? sliverContext,
  bool isFixedHeight = false,
}) async {
  if (animate) {
    return animateToIndex(
      index,
      duration: duration,
      curve: curve,
      alignment: alignment,
      padding: padding,
      sliverContext: sliverContext,
      isFixedHeight: isFixedHeight,
    );
  } else {
    return jumpToIndex(
      index,
      alignment: alignment,
      padding: padding,
      sliverContext: sliverContext,
      isFixedHeight: isFixedHeight,
    );
  }
}