Skip to main content

ScrollNotification

Trait ScrollNotification 

Source
pub trait ScrollNotification: LayoutChangedNotification + ViewportNotificationMixin {
    // Required method
    fn scroll_notification_data(&self) -> &ScrollNotificationData;

    // Provided methods
    fn metrics(&self) -> &Rc<dyn ScrollMetrics> { ... }
    fn context(&self) -> Option<BuildContext> { ... }
}
Expand description

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 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::set_state. 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).

To drive layout based on the scroll position, consider listening to the ScrollPosition directly (or indirectly via a ScrollController).

Required Methods§

Source

fn scroll_notification_data(&self) -> &ScrollNotificationData

Dart’s base-class fields, held under the field scroll_notification.

Provided Methods§

Source

fn metrics(&self) -> &Rc<dyn ScrollMetrics>

A description of a Scrollable’s contents, useful for modeling the state of its viewport.

Source

fn context(&self) -> Option<BuildContext>

The build context of the widget that fired this notification.

Trait Implementations§

Source§

impl NotificationTarget for dyn ScrollNotification

Source§

fn cast(notification: &dyn Notification) -> Option<&dyn ScrollNotification>

The notification as a T, when it is one.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§