animateToIndexAndOffset method
If the current origin-index is already the same as the given index
,
animates the position from its current value to the offset
position
relative to the origin-index.
The returned Future will complete when the animation ends, whether it completed successfully or whether it was interrupted prematurely.
However, if the current origin-index is different from the given index
,
this will jump to the new index, without any animation.
Implementation
Future<void> animateToIndexAndOffset({
required int index,
required double offset,
Duration duration = const Duration(milliseconds: 750),
Curve curve = Curves.decelerate,
}) async {
// If we didn't change origin, go to its 0.0 position.
if (_originIndex == index) {
_originIndex = index;
return super.animateTo(offset, duration: duration, curve: curve);
}
// If we changed the origin, jump to the index and offset.
else {
jumpToIndexAndOffset(index: index, offset: offset);
}
}