Scrollableprovides the interaction model for scrolling without specifying how the actual viewport is managed (a
ViewportBuildermust be provided). UI concerns are customized directly or via an inherited
ScrollConfigurationthat exposes an immutable
ScrollBehaviorinstance. This instance is used to build platform-specific chrome (i.e., a scrolling indicator) and provides ambient
ScrollPhysics, a class that describes how scrolling UI will respond to user gestures.
ScrollPhysicsis consulted throughout the framework to construct physics simulations for ballistic scrolling, to validate and adjust user interaction, to manage momentum across interactions, and to identify overscroll regions.
ScrollController. This controller is responsible for producing the
ScrollPositionfrom a given
ScrollPhysics; it also provides the
PageViewinjects a page-based scrolling mechanism by having its
PageController) return a custom scroll position subclass.
ScrollContextexposes build contexts for notifications and storage, a ticker provider for animations, and methods to interact with the scrollable; its analogous to
BuildContextfor an entire scrollable widget.
ScrollPositiontracks scroll offset as pixels (reporting changes via
Listenable), applies physics to interactions via
ScrollPhysics, and through subclasses like
ScrollActivityDelegateand makes concrete much of the actual scrolling machinery), starts and stops
ScrollActivityinstances to mutate the represented scroll position.
ScrollMetrics, which redundantly defines pixel offset and defines a number of other useful metrics like the amount of content above and below the current viewport (
extentAfter), the pixel offset corresponding to the top and bottom of the current viewport (
maxScrollExtent) and the viewport size (
ScrollPosition.correctPixels[replaces pixels outright] /
ViewportOffset.correctBy[applies a delta to pixels]) when the viewport is resized, as triggered by shrink wrapping or relayout. Every time a viewport (via
RenderViewport) is laid out, the new content extents are checked by
ViewportOffset.applyContentDimensionsto ensure the offset won’t change; if it does, layout must be repeated.
ViewportOffset.applyContentDimensionsare called to determine if this is the case; any extents provided represent viewport slack -- how far the viewport can be scrolled in either direction beyond what is already visible. Activities are notified via
ScrollControllerprovides a convenient interface for interacting with one or more
ScrollPositions; in effect, it calls the corresponding method in each of its positions. As a
Listenable, the controller aggregates notifications from its positions.
ScrollNotificationsare emitted by scrollable (by way of the active
ScrollActivity). As a
LayoutChangedNotificationsubclass, these are emitted after build and layout have already occurred, thus only painting can be performed in response without introduce jank.
ScrollPositionWithSingleContextstarts and manages
ScrollActivityinstances via drag,
jumpTo, and more.
ScrollActivityinstances update the scroll position via
ScrollPositionWithSingleContextimplements this interface and applies changes requested by the current activity (
applyUserOffset) and starts follow-on activities (
BallisticScrollActivityapply user-driven scrolling, animation-driven scrolling, and physics-driven scrolling, respectively.
ScrollPosition.beginActivitystarts activities and tracks all state changes. This is possible because the scroll position is always running an activity, even when idle (
IdleScrollActivity). These state changes generate scroll notifications via the activity.
Scrollableuses a gesture recognizer to detect and track dragging if
ScrollPhysics.shouldAcceptUserOffsetallows. When a drag begins, the
Scrollable’s scroll position is notified via
ScrollPositionWithSingleContextimplements this method to create a
ScrollDragControllerwhich serves as an integration point for the
Scrollable, which receives drag events, and the activity, which manages scroll state / notifications. The controller is returned as a
Draginstance, which provides a mechanism to update state as events arrive.
ScrollPositionWithSingleContext) which applies
ScrollPhysics.applyPhysicsToUserOffsetand, if valid, invokes
ScrollActivityDelegate.setPixels. This actually updates the scroll offset and generates scroll notifications.
ScrollActivityDelegate.goBallistic. This delegates to the scroll position’s
ScrollPhysicsinstance to determine how to react.
DragScrollActivitydelegates most of its work to the drag controller and is mainly responsible for forwarding scroll notifications.
DrivenScrollActivityis much more straightforward. It starts an animation controller which, on every tick, updates the current pixel value via
setPixels. When animating, if the container over-scrolls, an idle activity is started. If the animation completes successfully, a ballistic activity is started instead.
ScrollPositionwrites the current scroll offset to
ScrollViewis a base class that builds a scrollable and a viewport, deferring to its subclass to specify how its slivers are constructed. The subclass overrides
buildSliversto do this (
Scrollable, which uses
viewportBuilder, which uses
ScrollView.buildSliversto obtain the sliver children).