Skip to main content

Scrollable

Struct Scrollable 

Source
pub struct Scrollable {
    pub key: Option<KeyRef>,
    pub axis_direction: AxisDirection,
    pub controller: Option<ScrollControllerRef>,
    pub physics: Option<ScrollPhysicsRef>,
    pub viewport_builder: ViewportBuilder,
    pub increment_calculator: Option<ScrollIncrementCalculator>,
    pub hit_test_behavior: HitTestBehavior,
    pub drag_start_behavior: DragStartBehavior,
    pub restoration_id: Option<String>,
    pub scroll_behavior: Option<ScrollBehaviorRef>,
    pub clip_behavior: Clip,
}
Expand description

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.

The static Scrollable::of and Scrollable::ensure_visible 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 viewport_builder to customize the child model.

  2. You can provide a custom ScrollController that creates a custom ScrollPosition.

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

Fields§

§key: Option<KeyRef>§axis_direction: AxisDirection

The direction in which this widget scrolls.

For example, if the axis_direction is AxisDirection::Down, increasing the scroll position will cause content below the bottom of the viewport to become visible through the viewport. Similarly, if the axis direction is AxisDirection::Right, increasing the scroll position will cause content beyond the right edge of the viewport to become visible through the viewport.

Defaults to AxisDirection::Down.

§controller: Option<ScrollControllerRef>

An object that can be used to control the position to which this widget is scrolled.

A ScrollController serves several purposes. It can be used to control the initial scroll position, whether the scroll view should automatically save and restore its scroll position in the PageStorage, to read the current scroll position, or change it.

If None, a ScrollController will be created internally by Scrollable in order to create and manage the ScrollPosition.

§physics: Option<ScrollPhysicsRef>

How the widgets should respond to user input.

For example, determines how the widget continues to animate after the user stops dragging the scroll view.

Defaults to matching platform conventions via the physics provided from the ambient ScrollConfiguration.

If an explicit ScrollBehaviorRef is provided to scroll_behavior, the ScrollPhysics provided by that behavior will take precedence after this one.

The physics can be changed dynamically, but new physics will only take effect if the type of the provided object changes.

§viewport_builder: ViewportBuilder

Builds the viewport through which the scrollable content is displayed.

A typical viewport uses the given [AnyViewportOffset] to determine which part of its content is actually visible through the viewport.

§increment_calculator: Option<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 crate::ScrollAction.

If None, the default for crate::ScrollIncrementType::Page is 80% of the size of the scroll window, and for crate::ScrollIncrementType::Line, 50 logical pixels.

§hit_test_behavior: HitTestBehavior

Defines the behavior of the gesture detector used in this Scrollable.

This defaults to HitTestBehavior::Opaque which means it prevents targets behind this Scrollable from receiving events.

§drag_start_behavior: DragStartBehavior

Determines the way that drag start behavior is handled.

If set to DragStartBehavior::Start, scrolling drag behavior will begin at the position where the drag gesture won the arena. If set to DragStartBehavior::Down it will begin at the position where a down event is first detected.

By default, the drag start behavior is DragStartBehavior::Start.

§restoration_id: Option<String>

Restoration ID to save and restore the scroll offset of the scrollable.

If a restoration id is provided, the scrollable will persist its current scroll offset and restore it during state restoration.

The scroll offset is persisted in a RestorationBucket claimed from the surrounding RestorationScope using the provided restoration ID.

§scroll_behavior: Option<ScrollBehaviorRef>

A ScrollBehaviorRef that will be applied to this widget individually.

Defaults to None, wherein the inherited behavior is copied and modified to alter the viewport decoration.

A behavior also provides ScrollPhysics. If an explicit physics is provided in physics, it will take precedence, followed by this behavior, and then the inherited ancestor behavior.

§clip_behavior: Clip

The clip a decorator should honour.

Defaults to Clip::HardEdge.

This is passed to decorators in ScrollableDetails, and does not directly affect clipping of the Scrollable.

Implementations§

Source§

impl Scrollable

Source

pub fn new(viewport_builder: ViewportBuilder) -> Scrollable

Creates a widget that scrolls.

Source

pub fn key(self, key: KeyRef) -> Scrollable

Dart Scrollable(key:).

Source

pub fn axis_direction(self, axis_direction: AxisDirection) -> Scrollable

Dart Scrollable(axisDirection:).

Source

pub fn controller(self, controller: ScrollControllerRef) -> Scrollable

Dart Scrollable(controller:).

Source

pub fn physics(self, physics: ScrollPhysicsRef) -> Scrollable

Dart Scrollable(physics:).

Source

pub fn increment_calculator( self, increment_calculator: ScrollIncrementCalculator, ) -> Scrollable

Dart Scrollable(incrementCalculator:).

Source

pub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> Scrollable

Dart Scrollable(hitTestBehavior:).

Source

pub fn drag_start_behavior( self, drag_start_behavior: DragStartBehavior, ) -> Scrollable

Dart Scrollable(dragStartBehavior:).

Source

pub fn restoration_id(self, restoration_id: impl Into<String>) -> Scrollable

Dart Scrollable(restorationId:).

Source

pub fn scroll_behavior(self, scroll_behavior: ScrollBehaviorRef) -> Scrollable

Dart Scrollable(scrollBehavior:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> Scrollable

Dart Scrollable(clipBehavior:).

Source

pub fn axis(&self) -> Axis

The axis along which the scroll view scrolls.

Determined by the axis_direction.

Source

pub fn maybe_of( app: &mut App, context: BuildContext, axis: Option<Axis>, ) -> Option<Handle<ScrollableState>>

The state from the closest instance of this class that encloses the given context, or None if none is found.

Calling this method will create a dependency on the ScrollableState that is returned, if there is one. This is typically the closest Scrollable, but may be a more distant ancestor if axis is used to target a specific Scrollable.

Using the optional Axis is useful when scrollables are nested and the target Scrollable is not the closest instance.

This finds the nearest ancestor Scrollable of the context. This means that if the context is that of a Scrollable, it will not find that Scrollable.

See also:

Source

pub fn of( app: &mut App, context: BuildContext, axis: Option<Axis>, ) -> Handle<ScrollableState>

The state from the closest instance of this class that encloses the given context.

Calling this method will create a dependency on the ScrollableState that is returned.

§Panics

If no Scrollable ancestor is found.

See also:

Source

pub fn recommend_deferred_loading_for_context( app: &mut App, context: BuildContext, axis: Option<Axis>, ) -> bool

Provides a heuristic to determine if expensive frame-bound tasks should be deferred for the context at a specific point in time.

Calling this method does not create a dependency on any other widget. This also means that the value returned is only good for the point in time when it is called, and callers will not get updated if the value changes.

The heuristic used is determined by the physics of this Scrollable via ScrollPhysics::recommend_deferred_loading.

If there is no Scrollable in the widget tree above the context, this method returns false.

Source

pub fn ensure_visible( app: &mut App, context: BuildContext, alignment: f64, duration: Duration, curve: Rc<dyn Curve>, alignment_policy: ScrollPositionAlignmentPolicy, ) -> CompleterFuture<()> ⓘ

Scrolls all scrollables that enclose the given context so as to make the given context visible.

The returned future completes once every enclosing scrollable’s animation has ended.

Trait Implementations§

Source§

impl Debug for Scrollable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for Scrollable

Source§

type State = ScrollableState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn create_state(&self) -> ScrollableState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scrollable

§

impl !Send for Scrollable

§

impl !Sync for Scrollable

§

impl !UnwindSafe for Scrollable

§

impl Forget for Scrollable

§

impl Freeze for Scrollable
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, NonZero<u32>: Freeze, &'static ScrollControllerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn ScrollPhysics> is !null: Freeze, PhantomData<RcInner<dyn ScrollPhysics>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyViewportOffset>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyViewportOffset>) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Fn(&ScrollIncrementDetails) -> f64> is !null: Freeze, PhantomData<RcInner<dyn Fn(&ScrollIncrementDetails) -> f64>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn ScrollBehavior> is !null: Freeze, PhantomData<RcInner<dyn ScrollBehavior>>: Freeze,

§

impl Move for Scrollable

§

impl Unpin for Scrollable
where Rc<dyn Key>: Unpin, NonZero<u32>: Unpin, &'static ScrollControllerVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn ScrollPhysics>: Unpin, Rc<dyn Fn(&mut App, AnyElement, Retained<AnyViewportOffset>) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&ScrollIncrementDetails) -> f64>: Unpin, *const u8 is !null: Unpin, Rc<dyn ScrollBehavior>: Unpin,

§

impl UnsafeUnpin for Scrollable
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static ScrollControllerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn ScrollPhysics> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ScrollPhysics>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyViewportOffset>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyViewportOffset>) -> Rc<dyn Widget>>>: UnsafeUnpin, *const RcInner<dyn Fn(&ScrollIncrementDetails) -> f64> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&ScrollIncrementDetails) -> f64>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn ScrollBehavior> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ScrollBehavior>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>