ScrollPosition class
Determines which portion of the content is visible in a scroll view.
The pixels value determines the scroll offset that the scroll view uses to select which part of its content to display. As the user scrolls the viewport, this value changes, which changes the content that is displayed.
The ScrollPosition applies physics to scrolling, and stores the minScrollExtent and maxScrollExtent.
Scrolling is controlled by the current activity, which is set by beginActivity. ScrollPosition itself does not start any activities. Instead, concrete subclasses, such as ScrollPositionWithSingleContext, typically start activities in response to user input or instructions from a ScrollController.
This object is a Listenable that notifies its listeners when pixels changes.
Subclassing ScrollPosition
Over time, a Scrollable might have many different ScrollPosition objects. For example, if Scrollable.physics changes type, Scrollable creates a new ScrollPosition with the new physics. To transfer state from the old instance to the new instance, subclasses implement absorb. See absorb for more details.
Subclasses also need to call didUpdateScrollDirection whenever userScrollDirection changes values.
See also:
- Scrollable, which uses a ScrollPosition to determine which portion of its content to display.
- ScrollController, which can be used with ListView, GridView and other scrollable widgets to control a ScrollPosition.
- ScrollPositionWithSingleContext, which is the most commonly used concrete subclass of ScrollPosition.
- ScrollNotification and NotificationListener, which can be used to watch the scroll position without using a ScrollController.
- Inheritance
- Object
- ChangeNotifier
- ViewportOffset
- ScrollPosition
- Mixed in types
- Implementers
Constructors
- ScrollPosition({@required ScrollPhysics physics, @required ScrollContext context, bool keepScrollOffset: true, ScrollPosition oldPosition, String debugLabel })
- Creates an object that determines which portion of the content is visible in a scroll view. [...]
Properties
- activity → ScrollActivity
-
The currently operative ScrollActivity. [...]
@protected, read-only
- allowImplicitScrolling → bool
-
Whether a viewport is allowed to change pixels implicitly to respond to
a call to RenderObject.showOnScreen. [...]
read-only, override
- context → ScrollContext
-
Where the scrolling is taking place. [...]
final
- debugLabel → String
-
A label that is used in the toString output. [...]
final
- haveDimensions → bool
-
Whether viewportDimension, minScrollExtent, maxScrollExtent,
outOfRange, and atEdge are available. [...]
read-only
-
isScrollingNotifier
→ ValueNotifier<
bool> -
This notifier's value is true if a scroll is underway and false if the scroll
position is idle. [...]
final
- keepScrollOffset → bool
-
Save the current scroll offset with PageStorage and restore it if
this scroll position's scrollable is recreated. [...]
final
- maxScrollExtent → double
-
The maximum in-range value for pixels. [...]
read-only, override
- minScrollExtent → double
-
The minimum in-range value for pixels. [...]
read-only, override
- physics → ScrollPhysics
-
How the scroll position should respond to user input. [...]
final
- pixels → double
-
The number of pixels to offset the children in the opposite of the axis direction. [...]
read-only, override
- viewportDimension → double
-
The extent of the viewport along the axisDirection.
read-only, override
- atEdge → bool
-
Whether the pixels value is exactly at the minScrollExtent or the
maxScrollExtent.
read-only, inherited
- axis → Axis
-
The axis in which the scroll view scrolls.
read-only, inherited
- axisDirection → AxisDirection
-
The direction in which the scroll view scrolls.
read-only, inherited
- extentAfter → double
-
The quantity of content conceptually "below" the currently visible content
of the viewport in the scrollable. This is the content below the content
described by extentInside.
read-only, inherited
- extentBefore → double
-
The quantity of content conceptually "above" the currently visible content
of the viewport in the scrollable. This is the content above the content
described by extentInside.
read-only, inherited
- extentInside → double
-
The quantity of visible content. [...]
read-only, inherited
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- hasListeners → bool
-
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
- outOfRange → bool
-
Whether the pixels value is outside the minScrollExtent and
maxScrollExtent.
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- userScrollDirection → ScrollDirection
-
The direction in which the user is trying to change pixels, relative to
the viewport's
RenderViewport.axisDirection
. [...]read-only, inherited
Methods
-
absorb(
ScrollPosition other) → void -
Take any current applicable state from the given ScrollPosition. [...]
@mustCallSuper, @protected
-
animateTo(
double to, { Duration duration, Curve curve }) → Future< void> -
Animates the position from its current value to the given value. [...]
override
-
applyBoundaryConditions(
double value) → double -
Returns the overscroll by applying the boundary conditions. [...]
@protected
-
applyContentDimensions(
double minScrollExtent, double maxScrollExtent) → bool -
Called when the viewport's content extents are established. [...]
override
-
applyNewDimensions(
) → void -
Notifies the activity that the dimensions of the underlying viewport or
contents have changed. [...]
@mustCallSuper, @protected
-
applyViewportDimension(
double viewportDimension) → bool -
Called when the viewport's extents are established. [...]
override
-
beginActivity(
ScrollActivity newActivity) → void - Change the current activity, disposing of the old one and sending scroll notifications as necessary. [...]
-
correctBy(
double correction) → void -
Apply a layout-time correction to the scroll offset. [...]
override
-
correctPixels(
double value) → void - Change the value of pixels to the new value, without notifying any customers. [...]
-
debugFillDescription(
List< String> description) → void -
Add additional information to the given description for use by toString. [...]
override
-
didEndScroll(
) → void - Called by beginActivity to report when an activity has ended. [...]
-
didOverscrollBy(
double value) → void - Called by setPixels to report overscroll when an attempt is made to change the pixels position. Overscroll is the amount of change that was not applied to the pixels value.
-
didStartScroll(
) → void - Called by beginActivity to report when an activity has started.
-
didUpdateScrollDirection(
ScrollDirection direction) → void - Dispatches a notification that the userScrollDirection has changed. [...]
-
didUpdateScrollPositionBy(
double delta) → void - Called by setPixels to report a change to the pixels position.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener and removeListener will throw after the object is
disposed). [...]
override
-
drag(
DragStartDetails details, VoidCallback dragCancelCallback) → Drag - Start a drag activity corresponding to the given DragStartDetails. [...]
-
ensureVisible(
RenderObject object, { double alignment: 0.0, Duration duration: Duration.zero, Curve curve: Curves.ease }) → Future< void> - Animates the position such that the given object is as visible as possible by just scrolling this position.
-
forcePixels(
double value) → void -
Change the value of pixels to the new value, and notify any customers,
but without honoring normal conventions for changing the scroll offset. [...]
@protected
-
hold(
VoidCallback holdCancelCallback) → ScrollHoldController - Stop the current activity and start a HoldScrollActivity.
-
jumpTo(
double value) → void -
Jumps the scroll position from its current value to the given value,
without animation, and without checking if the new value is in range. [...]
override
-
jumpToWithoutSettling(
double value) → void -
Deprecated. Use jumpTo or a custom ScrollPosition instead.
@Deprecated('This will lead to bugs.')
-
moveTo(
double to, { Duration duration, Curve curve, bool clamp: true }) → Future< void> -
Calls jumpTo if duration is null or Duration.zero, otherwise
animateTo is called. [...]
override
-
notifyListeners(
) → void -
Call all the registered listeners. [...]
override
-
restoreScrollOffset(
) → void -
Called whenever the ScrollPosition is created, to restore the scroll
offset if possible. [...]
@protected
-
saveScrollOffset(
) → void -
Called whenever scrolling ends, to store the current scroll offset in a
storage mechanism with a lifetime that matches the app's lifetime. [...]
@protected
-
setPixels(
double newPixels) → double - Update the scroll position (pixels) to a given pixel value. [...]
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes. [...]
inherited
-
copyWith(
{double minScrollExtent, double maxScrollExtent, double pixels, double viewportDimension, AxisDirection axisDirection }) → ScrollMetrics -
Creates a ScrollMetrics that has the same properties as this object. [...]
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited