handleNotification method
Feeds a ScrollNotification to the state machine, for hosts that observe scrolling with a NotificationListener rather than owning a ScrollController.
The alternative to attach, for the shape attach cannot serve: an app-level scaffold wrapping arbitrary screen bodies has no way to reach whichever ScrollController the current screen happens to own, and on a tab bar each tab owns a different one. Use one source or the other — both at once counts every scroll twice.
NotificationListener<ScrollNotification>(
onNotification: (notification) {
_minimize.handleNotification(notification);
return false; // let it keep bubbling
},
child: body,
)
Horizontal notifications are ignored, so a carousel in the body cannot minimize the bar. Every vertical scroll view under the listener does drive it, so scope the listener to the body you want followed.
Implementation
void handleNotification(ScrollNotification notification) {
if (_disposed) return;
final metrics = notification.metrics;
if (metrics.axis != Axis.vertical) return;
if (notification is UserScrollNotification) {
_notificationDirection = notification.direction;
return;
}
// Only an update carries an offset change. Start, end and overscroll
// notifications would re-run the rules against an offset already sampled.
if (notification is! ScrollUpdateNotification) return;
handleSample(GlassTabBarScrollSample(
pixels: metrics.pixels,
minScrollExtent: metrics.minScrollExtent,
maxScrollExtent: metrics.maxScrollExtent,
viewportDimension: metrics.viewportDimension,
direction: _notificationDirection,
outOfRange: metrics.outOfRange,
));
}