animateToScroll method
void
animateToScroll(
- double scrollDelta,
- double scrollSpeed
)
Implementation
void animateToScroll(
double scrollDelta,
double scrollSpeed,
) {
if (scrollDelta > 0 != prevDeltaPositive) {
prevDeltaPositive = !prevDeltaPositive;
futurePosition =
clientController.offset + (scrollDelta * scrollSpeed * 0.5);
} else {
futurePosition = futurePosition + (scrollDelta * scrollSpeed * 0.5);
}
final Duration duration;
if (futurePosition > clientController.position.maxScrollExtent) {
futurePosition = isPlatformBouncingScrollPhysics
? min(clientController.position.maxScrollExtent + 150, futurePosition)
: clientController.position.maxScrollExtent;
duration =
Duration(milliseconds: silkyScrollDuration.inMilliseconds ~/ 2);
} else if (futurePosition < clientController.position.minScrollExtent) {
futurePosition = isPlatformBouncingScrollPhysics
? max(clientController.position.minScrollExtent - 150, futurePosition)
: clientController.position.minScrollExtent;
duration =
Duration(milliseconds: silkyScrollDuration.inMilliseconds ~/ 2);
} else {
duration = silkyScrollDuration;
}
isOnSilkyScrolling = true;
final Future<void> animationEnd =
_animationEnd = clientController.animateTo(
futurePosition,
duration: duration,
curve: animationCurve,
);
animationEnd.whenComplete(() {
if (animationEnd == _animationEnd) {
isOnSilkyScrolling = false;
if (clientController.hasClients == false) {
return;
}
double edgePosition = 0;
if (clientController.offset >
clientController.position.maxScrollExtent) {
isRecoilScroll = true;
edgePosition = clientController.position.maxScrollExtent;
} else if (clientController.offset <
clientController.position.minScrollExtent) {
isRecoilScroll = true;
edgePosition = clientController.position.minScrollExtent;
}
if (isRecoilScroll) {
notifyListeners();
clientController
.animateTo(
edgePosition,
duration: Duration(milliseconds: recoilDurationMS),
curve: Curves.easeInOutSine,
)
.whenComplete(() {
if (isAlive) {
isRecoilScroll = false;
notifyListeners();
}
});
}
}
});
}