animateToOffset method
Future
animateToOffset({
- required double offset,
- required IndicatorMode mode,
- Duration? duration,
- Curve curve = Curves.linear,
- bool jumpToEdge = true,
- ScrollController? scrollController,
override
Animates the position from its current value to the given value.
offset The offset to scroll to.
mode When duration is null and clamping is true, set the state.
jumpToEdge Whether to jump to the edge before scrolling.
duration See ScrollPosition.animateTo.
curve See ScrollPosition.animateTo.
scrollController When position is not ScrollPosition, you can use ScrollController.
Implementation
@override
Future animateToOffset({
required double offset,
required IndicatorMode mode,
Duration? duration,
Curve curve = Curves.linear,
bool jumpToEdge = true,
ScrollController? scrollController,
}) async {
final effectivePosition = _effectiveScrollPosition();
if (effectivePosition == null) {
return;
}
final matchedController =
_matchingScrollController(scrollController, effectivePosition);
final scrollTo = effectivePosition.maxScrollExtent + offset;
_releaseOffset = offset;
if (jumpToEdge) {
if (matchedController != null) {
matchedController.jumpTo(effectivePosition.maxScrollExtent);
} else {
effectivePosition.jumpTo(effectivePosition.maxScrollExtent);
}
}
if (clamping) {
if (duration == null) {
_offset = offset;
_mode = mode;
_updateBySimulation(effectivePosition, 0);
} else {
userOffsetNotifier.value = true;
_clampingAnimationController!.value = effectivePosition.maxScrollExtent;
await _clampingAnimationController!
.animateTo(scrollTo, duration: duration, curve: curve);
userOffsetNotifier.value = false;
_updateBySimulation(effectivePosition, 0);
}
} else {
if (duration == null) {
if (matchedController != null) {
matchedController.jumpTo(scrollTo);
} else {
effectivePosition.jumpTo(scrollTo);
}
} else {
userOffsetNotifier.value = true;
if (matchedController != null) {
await matchedController.animateTo(scrollTo,
duration: duration, curve: curve);
} else {
await effectivePosition.animateTo(scrollTo,
duration: duration, curve: curve);
}
userOffsetNotifier.value = false;
notifyListeners();
}
}
}