setPostPixels method
Implementation
double setPostPixels(
double newPixels,
double clipedOverscroll,
double systemOverscroll,
) {
final double overscroll =
overscrollOf(newPixels, minScrollExtent, maxScrollExtent);
final double oldPixels = pixels;
final double rawPixels = newPixels - overscroll;
final double overDelta = systemOverscroll - clipedOverscroll;
final isBouncing = overDelta.abs() > precisionErrorTolerance;
// Notifies that the scroll offset has changed.
void onNotify() {
if (pixels != oldPixels) {
notifyListeners();
didUpdateScrollPositionBy(pixels - oldPixels);
}
}
// First, apply clipped a given new pixels.
correctPixels(rawPixels);
final double available = isBouncing ? -overDelta : -clipedOverscroll;
final double consumed =
(isBouncing ? overDelta != 0.0 : clipedOverscroll != 0.0)
? _postScroll(available)
: 0.0;
clipedOverscroll += consumed;
/// It is also considered nested scrolling when the remaining
/// scroll amount is fully consumed in the post phase.
if ((consumed - available).abs() < precisionErrorTolerance) {
isNestedScrolling = true;
}
// When overscrolling is clipped or bouncing.
if (overDelta.abs() < precisionErrorTolerance) {
if (clipedOverscroll.abs() > precisionErrorTolerance) {
didOverscrollBy(clipedOverscroll);
onNotify();
return clipedOverscroll;
}
} else {
final double bouncingDelta = overDelta + consumed;
if (bouncingDelta.abs() > precisionErrorTolerance) {
final double consumed = _bouncing(bouncingDelta);
final double restDelta = bouncingDelta - consumed;
lentPixels += consumed;
if (restDelta.abs() > precisionErrorTolerance) {
correctBy(restDelta);
}
didOverscroll();
}
}
onNotify();
return 0.0;
}