Contains the state for common scrolling widgets that scroll only along one axis.

Widgets that subclass Scrollable typically use state objects that subclass ScrollableState.

The main state of a ScrollableState is the "scroll offset", which is the the logical description of the current scroll position and is stored in scrollOffset as a double. The units of the scroll offset are defined by the specific subclass. By default, the units are logical pixels.

A "pixel offset" is a distance in logical pixels (or a velocity in logical pixels per second). The pixel offset corresponding to the current scroll position is typically used as the paint offset argument to the underlying Viewport class (or equivalent); see the buildContent method.

A "pixel delta" is an Offset that describes a two-dimensional distance as reported by input events. If the scrolling convention is axis-aligned (as in a vertical scrolling list or a horizontal scrolling list), then the pixel delta will consist of a pixel offset in the scroll axis, and a value in the other axis that is either ignored (when converting to a scroll offset) or set to zero (when converting a scroll offset to a pixel delta).

If the units of the scroll offset are not logical pixels, then a mapping must be made from logical pixels (as used by incoming input events) and the scroll offset (as stored internally). To provide this mapping, override the pixelOffsetToScrollOffset and scrollOffsetToPixelOffset methods.

If the scrollable is not providing axis-aligned scrolling, then, to convert pixel deltas to scroll offsets and vice versa, override the pixelDeltaToScrollOffset and scrollOffsetToPixelOffset methods. By default, these assume an axis-aligned scroll behavior along the config.scrollDirection axis and are implemented in terms of the pixelOffsetToScrollOffset and scrollOffsetToPixelOffset methods.

Inheritance
Mixes-in
  • SingleTickerProviderStateMixin
Annotations
  • optionalTypeArgs

Constructors

ScrollableState()

Properties

scrollBehavior ExtentScrollBehavior

The current scroll behavior of this widget.

read-only
scrollOffset double

The current scroll offset.

read-only
shouldSnapScrollOffset bool

Whether this scrollable should attempt to snap scroll offsets.

read-only
virtualScrollOffset double

The current scroll offset, irrespective of the constraints defined by any ClampOverscrolls widget ancestors.

read-only
config → T

The current configuration.

read-only, inherited
context BuildContext

The location in the tree where this widget builds.

read-only, inherited
hashCode int

Get a hash code for this object.

read-only, inherited
mounted bool

Whether this State object is currently in a tree.

read-only, inherited
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) bool

The equality operator.

inherited

Methods

build(BuildContext context) Widget

Describes the part of the user interface represented by this widget.

buildContent(BuildContext context) Widget

Calls the widget's builder by default.

buildGestureDetectors() Map<Type, GestureRecognizerFactory>

Return the gesture detectors, in the form expected by RawGestureDetector.gestures and RawGestureDetectorState.replaceGestureRecognizers, that are applicable to this Scrollable in its current state.

createScrollBehavior() ExtentScrollBehavior

Use the value returned by ScrollConfiguration.createScrollBehavior. If this widget doesn't have a ScrollConfiguration ancestor, or its createScrollBehavior callback is null, then return a new instance of OverscrollWhenScrollableBehavior.

dependenciesChanged() → void

Called when a dependency of this State object changes.

didUpdateScrollBehavior(double newScrollOffset) → void

Update any in-progress scrolling physics to account for new scroll behavior.

dispatchOnScroll() → void

Calls the onScroll callback.

dispatchOnScrollEnd() → void

Calls the dispatchOnScrollEnd callback.

dispatchOnScrollStart() → void

Calls the onScrollStart callback.

dispose() → void

Called when this object is removed from the tree permanently.

fling(double scrollVelocity) Future<Null>

If scrollVelocity is greater than PixelScrollTolerance.velocity then fling the scroll offset with the given velocity in logical pixels/second. Otherwise, if this scrollable is overscrolled or a snapOffsetCallback was given, animate the scroll offset to its final value with settleScrollOffset.

handleExtentsChanged(double contentExtent, double containerExtent) → void

Updates the scroll behavior for the new content and container extent.

initState() → void

Called when this object is inserted into the tree.

pixelDeltaToScrollOffset(Offset pixelDelta) double

Returns the scroll offset component of the given pixel delta, accounting for the scroll direction and scroll anchor.

pixelOffsetToScrollOffset(double pixelOffset) double

Convert a position or velocity measured in terms of pixels to a scrollOffset. Scrollable gesture handlers convert their incoming values with this method. Subclasses that define scrollOffset in units other than pixels must override this method.

scrollBy(double scrollDelta, { Duration duration, Curve curve: Curves.ease, DragUpdateDetails details }) Future<Null>

Scroll this widget by the given scroll delta.

scrollOffsetToPixelDelta(double scrollOffset) Offset

Returns a two-dimensional representation of the scroll offset, accounting for the scroll direction and scroll anchor.

scrollOffsetToPixelOffset(double scrollOffset) double

Convert a scrollOffset value to the number of pixels to which it corresponds.

scrollTo(double newScrollOffset, { Duration duration, Curve curve: Curves.ease, DragUpdateDetails details }) Future<Null>

Scroll this widget to the given scroll offset.

settleScrollOffset() Future<Null>

Animate the scroll offset to a value with a local minima of energy.

snapScrollOffset(double scrollOffset) double

Returns the snapped offset closest to the given scroll offset.

updateGestureDetector() → void

Fixes up the gesture detector to listen to the appropriate gestures based on the current information about the layout.

createTicker(TickerCallback onTick) Ticker

Creates a ticker with the given callback.

inherited
deactivate() → void

Called when this object is removed from the tree.

inherited
debugFillDescription(List<String> description) → void

Add additional information to the given description for use by toString.

inherited
didUpdateConfig(T oldConfig) → void

Called whenever the configuration changes.

inherited
noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
reassemble() → void

Called whenever the application is reassembled during debugging.

inherited
setState(VoidCallback fn) → void

Notify the framework that the internal state of this object has changed.

inherited
toString() String

Returns a string representation of this object.

inherited