animateToOffset method
Future
animateToOffset({
- required double offset,
- required IndicatorMode mode,
- bool jumpToEdge = true,
- Duration? duration,
- Curve curve = Curves.linear,
- 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,
bool jumpToEdge = true,
Duration? duration,
Curve curve = Curves.linear,
ScrollController? scrollController,
}) async {
try {
if (scrollController == null && _position is! ScrollPosition) {
return;
}
} catch (_) {
return;
}
final scrollTo = -offset;
_releaseOffset = offset;
if (jumpToEdge) {
if (scrollController != null) {
scrollController
.jumpTo(scrollController.positions.first.minScrollExtent);
} else {
(_position as ScrollPosition).jumpTo(position.minScrollExtent);
}
}
if (clamping) {
if (duration == null) {
_offset = offset;
_mode = mode;
_updateBySimulation(position, 0);
} else {
userOffsetNotifier.value = true;
_clampingAnimationController!.value = position.minScrollExtent;
await _clampingAnimationController!
.animateTo(scrollTo, duration: duration, curve: curve);
userOffsetNotifier.value = false;
_updateBySimulation(position, 0);
}
} else {
if (_position is ScrollPosition) {
if (duration == null) {
if (scrollController != null) {
scrollController.jumpTo(scrollTo);
} else {
(_position as ScrollPosition).jumpTo(scrollTo);
}
} else {
userOffsetNotifier.value = true;
if (scrollController != null) {
await scrollController.animateTo(scrollTo,
duration: duration, curve: curve);
} else {
await (_position as ScrollPosition)
.animateTo(scrollTo, duration: duration, curve: curve);
}
userOffsetNotifier.value = false;
notifyListeners();
}
}
}
}