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:
-
You can provide a
viewport_builderto customize the child model. -
You can provide a custom
ScrollControllerthat creates a customScrollPosition.
§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: AxisDirectionThe 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: ViewportBuilderBuilds 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: HitTestBehaviorDefines 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: DragStartBehaviorDetermines 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: ClipThe 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
impl Scrollable
Sourcepub fn new(viewport_builder: ViewportBuilder) -> Scrollable
pub fn new(viewport_builder: ViewportBuilder) -> Scrollable
Creates a widget that scrolls.
Sourcepub fn key(self, key: KeyRef) -> Scrollable
pub fn key(self, key: KeyRef) -> Scrollable
Dart Scrollable(key:).
Sourcepub fn axis_direction(self, axis_direction: AxisDirection) -> Scrollable
pub fn axis_direction(self, axis_direction: AxisDirection) -> Scrollable
Dart Scrollable(axisDirection:).
Sourcepub fn controller(self, controller: ScrollControllerRef) -> Scrollable
pub fn controller(self, controller: ScrollControllerRef) -> Scrollable
Dart Scrollable(controller:).
Sourcepub fn physics(self, physics: ScrollPhysicsRef) -> Scrollable
pub fn physics(self, physics: ScrollPhysicsRef) -> Scrollable
Dart Scrollable(physics:).
Sourcepub fn increment_calculator(
self,
increment_calculator: ScrollIncrementCalculator,
) -> Scrollable
pub fn increment_calculator( self, increment_calculator: ScrollIncrementCalculator, ) -> Scrollable
Dart Scrollable(incrementCalculator:).
Sourcepub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> Scrollable
pub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> Scrollable
Dart Scrollable(hitTestBehavior:).
Sourcepub fn drag_start_behavior(
self,
drag_start_behavior: DragStartBehavior,
) -> Scrollable
pub fn drag_start_behavior( self, drag_start_behavior: DragStartBehavior, ) -> Scrollable
Dart Scrollable(dragStartBehavior:).
Sourcepub fn restoration_id(self, restoration_id: impl Into<String>) -> Scrollable
pub fn restoration_id(self, restoration_id: impl Into<String>) -> Scrollable
Dart Scrollable(restorationId:).
Sourcepub fn scroll_behavior(self, scroll_behavior: ScrollBehaviorRef) -> Scrollable
pub fn scroll_behavior(self, scroll_behavior: ScrollBehaviorRef) -> Scrollable
Dart Scrollable(scrollBehavior:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> Scrollable
pub fn clip_behavior(self, clip_behavior: Clip) -> Scrollable
Dart Scrollable(clipBehavior:).
Sourcepub fn axis(&self) -> Axis
pub fn axis(&self) -> Axis
The axis along which the scroll view scrolls.
Determined by the axis_direction.
Sourcepub fn maybe_of(
app: &mut App,
context: BuildContext,
axis: Option<Axis>,
) -> Option<Handle<ScrollableState>>
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:
Scrollable::of, which is similar to this method, but panics if noScrollableancestor is found.
Sourcepub fn of(
app: &mut App,
context: BuildContext,
axis: Option<Axis>,
) -> Handle<ScrollableState>
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:
Scrollable::maybe_of, which is similar to this method, but returnsNoneif noScrollableancestor is found.
Sourcepub fn recommend_deferred_loading_for_context(
app: &mut App,
context: BuildContext,
axis: Option<Axis>,
) -> bool
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.
Sourcepub fn ensure_visible(
app: &mut App,
context: BuildContext,
alignment: f64,
duration: Duration,
curve: Rc<dyn Curve>,
alignment_policy: ScrollPositionAlignmentPolicy,
) -> CompleterFuture<()> ⓘ
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
impl Debug for Scrollable
Source§impl StatefulWidget for Scrollable
impl StatefulWidget for Scrollable
Source§type State = ScrollableState
type State = ScrollableState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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
fn create_state(&self) -> ScrollableState
Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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 Scrollablewhere
*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 Scrollablewhere
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 Scrollablewhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.