onAttach property

ScrollControllerCallback? onAttach
finalinherited

Called when a ScrollPosition is attached to the scroll controller.

Since a scroll position is not attached until a Scrollable is actually built, this can be used to respond to a new position being attached.

At the time that a scroll position is attached, the ScrollMetrics, such as the ScrollMetrics.maxScrollExtent, are not yet available. These are not determined until the Scrollable has finished laying out its contents and computing things like the full extent of that content. ScrollPosition.hasContentDimensions can be used to know when the metrics are available, or a ScrollMetricsNotification can be used, discussed further below.

{@tool dartpad} This sample shows how to apply a listener to the ScrollPosition.isScrollingNotifier using ScrollController.onAttach. This is used to change the AppBar's color when scrolling is occurring.

** See code in examples/api/lib/widgets/scroll_position/scroll_controller_on_attach.0.dart ** {@end-tool}

Implementation

final ScrollControllerCallback? onAttach;