animateToIndex method
void
animateToIndex(})
Animates smoothly to a specific item index given a fixed
itemExtent in pixels.
Animation will be ignored when duration is zero.
- if scroll direction is
vertical,itemExtentis the computedheightof an item in the scrollable component's children. - if scroll direction is
horizontal,itemExtentis the computedwidthof an item in the scrollable component's children.
Example
final scrollController = ScrollController();
scrollController.animateToIndex(
5,
itemExtent: 100.0,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
Implementation
void animateToIndex(
int index, {
required double itemExtent,
Duration duration = const Duration(milliseconds: 300),
Curves curve = Curves.easeInOut,
}) {
animateTo(
index * itemExtent,
duration: duration,
curve: curve,
);
}