onNotification property Null safety

NotificationListenerCallback<T>? onNotification

Called when a notification of the appropriate type arrives at this location in the tree.

Return true to cancel the notification bubbling. Return false to allow the notification to continue to be dispatched to further ancestors.

Notifications vary in terms of when they are dispatched. There are two main possibilities: dispatch between frames, and dispatch during layout.

For notifications that dispatch during layout, such as those that inherit from LayoutChangedNotification, it is too late to call State.setState in response to the notification (as layout is currently happening in a descendant, by definition, since notifications bubble up the tree). For widgets that depend on layout, consider a LayoutBuilder instead.


final NotificationListenerCallback<T>? onNotification;