Skip to main content

PageView

Struct PageView 

Source
pub struct PageView {
Show 16 fields pub key: Option<KeyRef>, pub allow_implicit_scrolling: bool, pub scroll_cache_extent: Option<ScrollCacheExtent>, pub restoration_id: Option<String>, pub scroll_direction: Axis, pub reverse: bool, pub controller: Option<Retained<Handle<PageController>>>, pub physics: Option<Rc<dyn ScrollPhysics>>, pub page_snapping: bool, pub on_page_changed: Option<Rc<dyn Fn(&mut App, i32)>>, pub children_delegate: Rc<dyn SliverChildDelegate>, pub drag_start_behavior: DragStartBehavior, pub clip_behavior: Clip, pub hit_test_behavior: HitTestBehavior, pub scroll_behavior: Option<ScrollBehaviorRef>, pub pad_ends: bool,
}
Expand description

A scrollable list that works page by page.

Each child of a page view is forced to be the same size as the viewport.

You can use a PageController to control which page is visible in the view. In addition to being able to control the pixel offset of the content inside the PageView, a PageController also lets you control the offset in terms of pages, which are increments of the viewport size.

The PageController can also be used to control the PageController::initial_page, which determines which page is shown when the PageView is first constructed, and the PageController::viewport_fraction, which determines the size of the pages as a fraction of the viewport size.

§Persisting the scroll position during a session

Scroll views attempt to persist their scroll position using PageStorage. For a PageView, this can be disabled by setting PageController::keep_page to false on the controller. If it is enabled, using a PageStorageKey for the key of this widget is recommended to help disambiguate different scroll views from each other.

See also:

  • PageController, which controls which page is visible in the view.
  • SingleChildScrollView, when you need to make a single child scrollable.
  • ListView, for a scrollable list of boxes.
  • GridView, for a scrollable grid of boxes.
  • ScrollNotification and NotificationListener, which can be used to watch the scroll position without using a ScrollController.

Fields§

§key: Option<KeyRef>§allow_implicit_scrolling: bool

Controls whether the widget’s pages will respond to RenderObject.showOnScreen, which will allow for implicit accessibility scrolling.

With this flag set to false, when accessibility focus reaches the end of the current page and the user attempts to move it to the next element, the focus will traverse to the next widget outside of the page view.

With this flag set to true, when accessibility focus reaches the end of the current page and user attempts to move it to the next element, focus will traverse to the next page in the page view.

§scroll_cache_extent: Option<ScrollCacheExtent>

The amount of content to lay out around the visible pages; None until given.

In PageView, the default uses ScrollCacheExtent::Viewport, where the value represents the number of viewport lengths to cache beyond the visible area.

When PageController::viewport_fraction is 1.0 (the default), this is equivalent to the number of pages. For example, ScrollCacheExtent::Viewport(2.0) caches 2 pages before and after the visible page.

When PageController::viewport_fraction is less than 1.0, multiple pages may be visible in a single viewport, so ScrollCacheExtent::Viewport(1.0) may cache more than one additional page in each direction.

ScrollCacheExtent::Pixels can also be used to specify the cache extent in logical pixels instead of viewport sizes.

If it is given, its value must be consistent with allow_implicit_scrolling: the value must be greater than 0.0 when allow_implicit_scrolling is true, and must be 0.0 when it is false.

Defaults to ScrollCacheExtent::Viewport(1.0) if allow_implicit_scrolling is true, and ScrollCacheExtent::Viewport(0.0) if it is false; read it through effective_scroll_cache_extent.

§restoration_id: Option<String>

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

§scroll_direction: Axis

The Axis along which the scroll view’s offset increases with each page.

For the direction in which active scrolling may be occurring, see ScrollDirection.

Defaults to Axis::Horizontal.

§reverse: bool

Whether the page view scrolls in the reading direction.

For example, if the reading direction is left-to-right and scroll_direction is Axis::Horizontal, then the page view scrolls from left to right when reverse is false and from right to left when reverse is true.

Similarly, if scroll_direction is Axis::Vertical, then the page view scrolls from top to bottom when reverse is false and from bottom to top when reverse is true.

Defaults to false.

§controller: Option<Retained<Handle<PageController>>>

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

§physics: Option<Rc<dyn ScrollPhysics>>

How the page view should respond to user input.

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

The physics are modified to snap to page boundaries using PageScrollPhysics prior to being used.

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

Defaults to matching platform conventions.

§page_snapping: bool

Set to false to disable page snapping, useful for custom scroll behavior.

If the pad_ends is false and PageController::viewport_fraction < 1.0, the page will snap to the beginning of the viewport; otherwise, the page will snap to the center of the viewport.

§on_page_changed: Option<Rc<dyn Fn(&mut App, i32)>>

Called whenever the page in the center of the viewport changes.

§children_delegate: Rc<dyn SliverChildDelegate>

A delegate that provides the children for the PageView.

The PageView::custom constructor lets you specify this delegate explicitly. The PageView::new and PageView::builder constructors create a children_delegate that wraps the given list and builder, respectively.

§drag_start_behavior: DragStartBehavior

Determines the way that drag start behavior is handled.

§clip_behavior: Clip

The content will be clipped (or not) according to this option.

Defaults to Clip::HardEdge.

§hit_test_behavior: HitTestBehavior

Defines the behavior of gesture detector used in this Scrollable.

Defaults to HitTestBehavior::Opaque.

§scroll_behavior: Option<ScrollBehaviorRef>

A ScrollBehaviorRef that will be applied to this widget individually.

The scroll behavior of the inherited ScrollConfiguration will be modified by default to not apply a scrollbar.

§pad_ends: bool

Whether to add padding to both ends of the list.

If this is set to true and PageController::viewport_fraction < 1.0, padding will be added such that the first and last child slivers will be in the center of the viewport when scrolled all the way to the start or end, respectively.

If PageController::viewport_fraction >= 1.0, this property has no effect.

This property defaults to true.

Implementations§

Source§

impl PageView

Source

pub fn new() -> PageView

Creates a scrollable list that works page by page from an explicit list of widgets, which the children setter supplies.

This constructor is appropriate for page views with a small number of children because constructing the list requires doing work for every child that could possibly be displayed in the page view, instead of just those children that are actually visible.

Source

pub fn builder( item_builder: impl Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>> + 'static, ) -> PageViewBuilder

Creates a scrollable list that works page by page using widgets that are created on demand.

This constructor is appropriate for page views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

Providing an item_count lets the PageView compute the maximum scroll extent.

The item builder will be called only with indices greater than or equal to zero and less than the item count.

Source

pub fn custom(children_delegate: Rc<dyn SliverChildDelegate>) -> PageView

Creates a scrollable list that works page by page with a custom child model.

Source

pub fn children( self, children: impl IntoIterator<Item = Rc<dyn Widget>>, ) -> PageView

Dart PageView(children:), which wraps the list in a SliverChildListDelegate.

Source

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

Dart PageView(key:).

Source

pub fn scroll_direction(self, scroll_direction: Axis) -> PageView

Dart PageView(scrollDirection:).

Source

pub fn reverse(self, reverse: bool) -> PageView

Dart PageView(reverse:).

Source

pub fn controller( self, controller: Retained<Handle<PageController>>, ) -> PageView

Dart PageView(controller:).

Source

pub fn physics(self, physics: Rc<dyn ScrollPhysics>) -> PageView

Dart PageView(physics:).

Source

pub fn page_snapping(self, page_snapping: bool) -> PageView

Dart PageView(pageSnapping:).

Source

pub fn on_page_changed( self, on_page_changed: impl Fn(&mut App, i32) + 'static, ) -> PageView

Dart PageView(onPageChanged:).

Source

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

Dart PageView(dragStartBehavior:).

Source

pub fn allow_implicit_scrolling( self, allow_implicit_scrolling: bool, ) -> PageView

Dart PageView(allowImplicitScrolling:).

Source

pub fn scroll_cache_extent( self, scroll_cache_extent: ScrollCacheExtent, ) -> PageView

Dart PageView(scrollCacheExtent:).

Source

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

Dart PageView(restorationId:).

Source

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

Dart PageView(clipBehavior:).

Source

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

Dart PageView(hitTestBehavior:).

Source

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

Dart PageView(scrollBehavior:).

Source

pub fn pad_ends(self, pad_ends: bool) -> PageView

Dart PageView(padEnds:).

Source

pub fn effective_scroll_cache_extent(&self) -> ScrollCacheExtent

Dart’s scrollCacheExtent field, as its constructor fills it.

Trait Implementations§

Source§

impl Debug for PageView

Source§

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

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

impl Default for PageView

Source§

fn default() -> PageView

Returns the “default value” for a type. Read more
Source§

impl StatefulWidget for PageView

Source§

type State = PageViewState

The state this widget creates.
Source§

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

Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> PageViewState

Creates the mutable state for this widget at a given location in the tree. Read more
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 as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

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 PageView

§

impl !Send for PageView

§

impl !Sync for PageView

§

impl !UnwindSafe for PageView

§

impl Forget for PageView

§

impl Freeze for PageView
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, NonZero<u32>: Freeze, PhantomData<fn() -> PageController>: 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, i32)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, i32)>>: Freeze, *const RcInner<dyn SliverChildDelegate> is !null: Freeze, PhantomData<RcInner<dyn SliverChildDelegate>>: Freeze, *const RcInner<dyn ScrollBehavior> is !null: Freeze, PhantomData<RcInner<dyn ScrollBehavior>>: Freeze,

§

impl Move for PageView

§

impl Unpin for PageView
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, NonZero<u32>: Unpin, Rc<Keep>: Unpin, Rc<dyn ScrollPhysics>: Unpin, Rc<dyn Fn(&mut App, i32)>: Unpin, Rc<dyn SliverChildDelegate>: Unpin, Rc<dyn ScrollBehavior>: Unpin,

§

impl UnsafeUnpin for PageView
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, PhantomData<fn() -> PageController>: 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, i32)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, i32)>>: UnsafeUnpin, *const RcInner<dyn SliverChildDelegate> is !null: UnsafeUnpin, PhantomData<RcInner<dyn SliverChildDelegate>>: 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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more