Scrollable class

A widget that manages scrolling in one dimension and informs the Viewport through which the content is viewed.

Scrollable implements the interaction model for a scrollable widget, including gesture recognition, but does not have an opinion about how the viewport, which actually displays the children, is constructed.

It's rare to construct a Scrollable directly. Instead, consider ListView or GridView, which combine scrolling, viewporting, and a layout model. To combine layout models (or to use a custom layout mode), consider using CustomScrollView.

The static Scrollable.of and Scrollable.ensureVisible functions are often used to interact with the Scrollable widget inside a ListView or a GridView.

To further customize scrolling behavior with a Scrollable:

  1. You can provide a viewportBuilder to customize the child model. For example, SingleChildScrollView uses a viewport that displays a single box child whereas CustomScrollView uses a Viewport or a ShrinkWrappingViewport, both of which display a list of slivers.

  2. You can provide a custom ScrollController that creates a custom ScrollPosition subclass. For example, PageView uses a PageController, which creates a page-oriented scroll position subclass that keeps the same page visible when the Scrollable resizes.

Persisting the scroll position during a session

Scrollables attempt to persist their scroll position using PageStorage. This can be disabled by setting ScrollController.keepScrollOffset to false on the controller. If it is enabled, using a PageStorageKey for the key of this widget (or one of its ancestors, e.g. a ScrollView) is recommended to help disambiguate different Scrollables from each other.

See also:



Scrollable({Key? key, AxisDirection axisDirection = AxisDirection.down, ScrollController? controller, ScrollPhysics? physics, required ViewportBuilder viewportBuilder, ScrollIncrementCalculator? incrementCalculator, bool excludeFromSemantics = false, int? semanticChildCount, DragStartBehavior dragStartBehavior = DragStartBehavior.start, String? restorationId, ScrollBehavior? scrollBehavior, Clip clipBehavior = Clip.hardEdge})
Creates a widget that scrolls.


axis Axis
The axis along which the scroll view scrolls.
no setter
axisDirection AxisDirection
The direction in which this widget scrolls.
clipBehavior Clip
The content will be clipped (or not) according to this option.
controller ScrollController?
An object that can be used to control the position to which this widget is scrolled.
dragStartBehavior DragStartBehavior
Determines the way that drag start behavior is handled.
excludeFromSemantics bool
Whether the scroll actions introduced by this Scrollable are exposed in the semantics tree.
hashCode int
The hash code for this object.
no setterinherited
incrementCalculator ScrollIncrementCalculator?
An optional function that will be called to calculate the distance to scroll when the scrollable is asked to scroll via the keyboard using a ScrollAction.
key Key?
Controls how one widget replaces another widget in the tree.
physics ScrollPhysics?
How the widgets should respond to user input.
restorationId String?
Restoration ID to save and restore the scroll offset of the scrollable.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollBehavior ScrollBehavior?
A ScrollBehavior that will be applied to this widget individually.
semanticChildCount int?
The number of children that will contribute semantic information.
viewportBuilder ViewportBuilder
Builds the viewport through which the scrollable content is displayed.


createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
createState() ScrollableState
Creates the mutable state for this widget at a given location in the tree.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator.

Static Methods

ensureVisible(BuildContext context, {double alignment = 0.0, Duration duration =, Curve curve = Curves.ease, ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit}) Future<void>
Scrolls the scrollables that enclose the given context so as to make the given context visible.
maybeOf(BuildContext context, {Axis? axis}) ScrollableState?
The state from the closest instance of this class that encloses the given context, or null if none is found.
of(BuildContext context, {Axis? axis}) ScrollableState
The state from the closest instance of this class that encloses the given context.
recommendDeferredLoadingForContext(BuildContext context, {Axis? axis}) bool
Provides a heuristic to determine if expensive frame-bound tasks should be deferred for the context at a specific point in time.