setPixels method
Updates the given appbar based on available scroll offset, the current appbar position, and the nested scroll position.
Implementation
@override
double setPixels(
double available,
AppBarPosition appBar,
NestedScrollPosition scroll,
) {
assert(
floating ? !dragOnlyExpanding : true,
"[floating] and [dragOnlyExpanding] cannot be used together.",
);
// APPBAR SCROLLING CONSTRAINTS
// No consume when bouncing overscroll for appbar pixels safety.
if (scroll.totalPixels < scroll.minScrollExtent || scroll.totalPixels > scroll.maxScrollExtent) {
return 0;
}
if (!floating) {
// No consume when scroll offset is zero ~ infinity.
if (scroll.pixels > precisionErrorTolerance) return 0;
if (dragOnlyExpanding && scroll.isBallisticScrolling && appBar.shrinkedPercent == 1) {
return 0;
}
}
if (!alwaysScrolling) {
if (appBar.extent > scroll.maxScrollExtent + appBar.pixels) return 0;
}
final double consumed = appBar.setPixelsWithDelta(available);
final double minScrollExtent = scroll.minScrollExtent;
final double maxScrollExtent = scroll.maxScrollExtent;
// When the appbar scrolls the layout intrinsic size changes so this
// information is preemptively communicated to the [ScrollPosition].
if (consumed.abs() > precisionErrorTolerance) {
scroll.applyContentDimensions(
minScrollExtent,
max(minScrollExtent, maxScrollExtent + consumed),
);
}
return consumed;
}