ScrollNotification class abstract

A Notification related to scrolling.

Scrollable widgets notify their ancestors about scrolling-related changes. The notifications have the following lifecycle:

Notifications bubble up through the tree, which means a given NotificationListener will receive notifications for all descendant Scrollable widgets. To focus on notifications from the nearest Scrollable descendant, check that the depth property of the notification is zero.

When a scroll notification is received by a NotificationListener, the listener will have already completed build and layout, and it is therefore too late for that widget to call State.setState. Any attempt to adjust the build or layout based on a scroll notification would result in a layout that lagged one frame behind, which is a poor user experience. Scroll notifications are therefore primarily useful for paint effects (since paint happens after layout). The GlowingOverscrollIndicator and Scrollbar widgets are examples of paint effects that use scroll notifications.

This sample shows the difference between using a ScrollController or a NotificationListener of type ScrollNotification to listen to scrolling activities. Toggling the Radio button switches between the two. Using a ScrollNotification will provide details about the scrolling activity, along with the metrics of the ScrollPosition, but not the scroll position object itself. By listening with a ScrollController, the position object is directly accessible. Both of these types of notifications are only triggered by scrolling.

To create a local project with this code sample, run:
flutter create --sample=widgets.ScrollNotification.1 mysample

To drive layout based on the scroll position, consider listening to the ScrollPosition directly (or indirectly via a ScrollController). This will not notify when the ScrollMetrics of a given scroll position changes, such as when the window is resized, changing the dimensions of the Viewport. In order to listen to changes in scroll metrics, use a NotificationListener of type ScrollMetricsNotification. This type of notification differs from ScrollNotification, as it is not associated with the activity of scrolling, but rather the dimensions of the scrollable area.

This sample shows how a ScrollMetricsNotification is dispatched when the windowSize is changed. Press the floating action button to increase the scrollable window's size.

To create a local project with this code sample, run:
flutter create --sample=widgets.ScrollNotification.2 mysample

Mixed in types


ScrollNotification({required ScrollMetrics metrics, required BuildContext? context})
Initializes fields for subclasses.


context BuildContext?
The build context of the widget that fired this notification.
depth int
The number of viewports that this notification has bubbled through.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
metrics ScrollMetrics
A description of a Scrollable's contents, useful for modeling the state of its viewport.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


debugFillDescription(List<String> description) → void
Add additional information to the given description for use by toString.
dispatch(BuildContext? target) → void
Start bubbling this notification at the given build context.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.