Skip to main content

Notification

Trait Notification 

Source
pub trait Notification: Any + Debug {
    // Required method
    fn as_any(&self) -> &(dyn Any + 'static);

    // Provided methods
    fn viewport_depth(&self) -> Option<&Cell<u32>> { ... }
    fn as_scroll_notification(
        &self,
    ) -> Option<&(dyn ScrollNotification + 'static)> { ... }
    fn as_layout_changed_notification(
        &self,
    ) -> Option<&(dyn LayoutChangedNotification + 'static)> { ... }
    fn dispatch(&self, app: &mut App, target: Option<AnyElement>)
       where Self: Sized { ... }
}
Expand description

To send a notification, call dispatch on the notification you wish to send. The notification will be delivered to any NotificationListener widgets with the appropriate type parameters that are ancestors of the given BuildContext. A notification that can bubble up the widget tree.

You can determine the type of a notification using the is operator to check the runtimeType of the notification; here as_any and a downcast.

To listen for notifications in a subtree, use a NotificationListener.

Required Methods§

Source

fn as_any(&self) -> &(dyn Any + 'static)

The notification as Any, for Dart’s notification is T check.

Provided Methods§

Source

fn viewport_depth(&self) -> Option<&Cell<u32>>

The depth counter of a notification that mixes in ViewportNotificationMixin (widgets/scroll_notification.rs), for the viewport elements that increment it as the notification bubbles past them; None — the default — for every other notification.

This is Dart’s notification is ViewportNotificationMixin: a mixin is an interface, not a type, so an erased notification answers the check from its own vtable rather than through as_any. The counter is a Cell because a notification bubbles as &dyn Notification.

Source

fn as_scroll_notification(&self) -> Option<&(dyn ScrollNotification + 'static)>

The notification as a ScrollNotification (widgets/scroll_notification.rs), for a NotificationListener<dyn ScrollNotification>; None — the default — for every other notification.

This is Dart’s notification is ScrollNotification, answered from the vtable as viewport_depth is, because the family is a trait.

Source

fn as_layout_changed_notification( &self, ) -> Option<&(dyn LayoutChangedNotification + 'static)>

The notification as a LayoutChangedNotification (widgets/notification_listener.rs), for a NotificationListener<dyn LayoutChangedNotification>; None — the default — for every other notification.

This is Dart’s notification is LayoutChangedNotification, answered from the vtable as as_scroll_notification is: every notification Dart derives from LayoutChangedNotification answers it, scroll notifications included.

Source

fn dispatch(&self, app: &mut App, target: Option<AnyElement>)
where Self: Sized,

Start bubbling this notification at the given build context.

The notification will be delivered to any NotificationListener widgets with the appropriate type parameters that are ancestors of the given BuildContext. If the BuildContext is null, the notification is not dispatched.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§