animateToList method

Future<void> animateToList(
  1. int listIndex, {
  2. Duration duration = const Duration(milliseconds: 400),
  3. Curve curve = Curves.ease,
})

Animates to a specific list index

Implementation

Future<void> animateToList(int listIndex, {
  Duration duration = const Duration(milliseconds: 400),
  Curve curve = Curves.ease,
}) async {
  if (!isAttached || _isDisposed) return;

  try {
    _setAnimating(true);
    final targetOffset = listIndex * _itemWidth;
    await _scrollController!.animateTo(
      targetOffset,
      duration: duration,
      curve: curve,
    );
  } catch (e, stackTrace) {
    _callbacks?.onError?.call('Failed to animate to list $listIndex: $e', stackTrace);
  } finally {
    _setAnimating(false);
  }
}