onAttach property

ScrollControllerCallback? onAttach
final

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.

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.
link

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

Implementation

final ScrollControllerCallback? onAttach;