Skip to main content

ScrollView

Trait ScrollView 

Source
pub trait ScrollView:
    Clone
    + Debug
    + Sized
    + 'static {
    // Required methods
    fn scroll_view_data(&self) -> &ScrollViewData;
    fn scroll_view_data_mut(&mut self) -> &mut ScrollViewData;
    fn build_slivers(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> Vec<WidgetRef>;

    // Provided methods
    fn get_direction(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> AxisDirection { ... }
    fn build_viewport(
        &self,
        app: &mut App,
        context: BuildContext,
        offset: ViewportOffsetRef,
        axis_direction: AxisDirection,
        slivers: Vec<WidgetRef>,
    ) -> WidgetRef { ... }
}
Expand description

A widget that combines a Scrollable and a Viewport to create an interactive scrolling pane of content in one dimension.

Scrollable widgets consist of three pieces:

  1. A Scrollable widget, which listens for various user gestures and implements the interaction design for scrolling.
  2. A viewport widget, such as Viewport or ShrinkWrappingViewport, which implements the visual design for scrolling by displaying only a portion of the widgets inside the scroll view.
  3. One or more slivers, which are widgets that can be composed to create various scrolling effects, such as lists, grids, and expanding headers.

ScrollView helps orchestrate these pieces by creating the Scrollable and the viewport and deferring to its implementor to create the slivers.

Dart’s abstract ScrollView is this trait over a ScrollViewData bag; the shared build body lives on ScrollViewBase, which an implementor’s StatelessWidget::build calls.

§Persisting the scroll position during a session

Scroll views attempt to persist their scroll position using PageStorage. This can be disabled by setting ScrollControllerLeaf::keep_scroll_offset to false on the controller.

Required Methods§

Source

fn scroll_view_data(&self) -> &ScrollViewData

Source

fn scroll_view_data_mut(&mut self) -> &mut ScrollViewData

The ScrollViewData bag, mutably.

Source

fn build_slivers(&self, app: &mut App, context: BuildContext) -> Vec<WidgetRef>

Build the list of widgets to place inside the viewport.

Implementors override this method to build the slivers for the inside of the viewport.

Provided Methods§

Source

fn get_direction(&self, app: &mut App, context: BuildContext) -> AxisDirection

Returns the AxisDirection in which the scroll view scrolls.

Combines the ScrollViewData::scroll_direction with the ScrollViewData::reverse boolean to obtain the concrete AxisDirection.

If the scroll direction is Axis::Horizontal, the ambient Directionality is also considered when selecting the concrete AxisDirection.

Source

fn build_viewport( &self, app: &mut App, context: BuildContext, offset: ViewportOffsetRef, axis_direction: AxisDirection, slivers: Vec<WidgetRef>, ) -> WidgetRef

Build the viewport.

Implementors may override this method to change how the viewport is built. The default implementation uses a ShrinkWrappingViewport if ScrollViewData::shrink_wrap is true, and a regular Viewport otherwise.

The offset argument is the value obtained from Scrollable::viewport_builder.

The axis_direction argument is the value obtained from get_direction.

The slivers argument is the value obtained from build_slivers.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§