Skip to main content

ListView

Struct ListView 

Source
pub struct ListView {
    pub item_extent: Option<f64>,
    pub item_extent_builder: Option<ItemExtentBuilder>,
    pub prototype_item: Option<WidgetRef>,
    pub children_delegate: SliverChildDelegateRef,
    /* private fields */
}
Expand description

A scrollable list of widgets arranged linearly.

ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView.

If non-None, the item_extent forces the children to have the given extent in the scroll direction. Specifying an item extent is more efficient than letting the children determine their own extent because the scrolling machinery can make use of the foreknowledge of the children’s extent to save work, for example when the scroll position changes drastically.

If non-None, the prototype_item forces the children to have the same extent as the given widget in the scroll direction. You can’t specify more than one of item_extent, prototype_item and item_extent_builder.

There are four ways to construct a ListView:

  1. ListView::new takes an explicit list of children through the children setter. This is appropriate for list views with a small number of children because constructing the list requires doing work for every child that could possibly be displayed in the list view instead of just those children that are actually visible.

  2. ListView::builder takes an item builder, which builds the children on demand. This is appropriate for list views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

  3. ListView::separated takes two builders: item_builder builds child items on demand, and separator_builder similarly builds separator children which appear in between the child items. This is appropriate for list views with a fixed number of children.

  4. ListView::custom takes a SliverChildDelegateRef, which provides the ability to customize additional aspects of the child model.

By default, a ListView will automatically pad the list’s scrollable extremities to avoid partial obstructions indicated by the MediaQuery’s padding. To avoid this behavior, override with a zero padding.

§Transitioning to CustomScrollView

A ListView is basically a CustomScrollView with a single SliverList in its CustomScrollView::slivers property. The padding corresponds to having a SliverPadding in the slivers instead of the list itself, and having the SliverList instead be a child of the SliverPadding.

Fields§

§item_extent: Option<f64>

If non-None, forces the children to have the given extent in the scroll direction.

Specifying an item extent is more efficient than letting the children determine their own extent because the scrolling machinery can make use of the foreknowledge of the children’s extent to save work, for example when the scroll position changes drastically.

§item_extent_builder: Option<ItemExtentBuilder>

If non-None, forces the children to have the corresponding extent returned by the builder.

Specifying an item extent builder is more efficient than letting the children determine their own extent because the scrolling machinery can make use of the foreknowledge of the children’s extent to save work, for example when the scroll position changes drastically.

§prototype_item: Option<WidgetRef>

If non-None, forces the children to have the same extent as the given widget in the scroll direction.

Specifying a prototype item is more efficient than letting the children determine their own extent because the scrolling machinery can make use of the foreknowledge of the children’s extent to save work, for example when the scroll position changes drastically.

See also:

  • SliverPrototypeExtentList, the sliver used internally when this property is provided. It constrains its box children to have the same extent as a prototype item along the main axis.
  • The item_extent property, which allows forcing the children’s extent to a given value.
  • The item_extent_builder property, which allows forcing the children’s extent to be the value returned by the callback.
§children_delegate: SliverChildDelegateRef

A delegate that provides the children for the ListView.

The SliverList::delegate property corresponds to this one.

Implementations§

Source§

impl ListView

Source

pub fn new() -> ListView

Creates a scrollable, linear array of widgets from an explicit list, which the children setter supplies.

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

It is usually more efficient to create children on demand using ListView::builder.

Source

pub fn builder( item_builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static, ) -> ListViewBuilder

Creates a scrollable, linear array of widgets that are created on demand.

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

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

Source

pub fn separated( item_builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static, separator_builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static, item_count: i32, ) -> ListViewSeparated

Creates a fixed-length scrollable linear array of list “items” separated by list item “separators”.

This constructor is appropriate for list views with a large number of item and separator children because the builders are only called for the children that are actually visible.

The separator_builder is similar to item_builder, except it is the widget that gets placed between item_builder(context, index) and item_builder(context, index + 1).

Source

pub fn custom(children_delegate: SliverChildDelegateRef) -> ListView

Creates a scrollable, linear array of widgets with a custom child model.

For example, a custom child model can control the algorithm used to estimate the size of children that are not actually visible.

Source

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

Dart key:.

Source

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

Dart scrollDirection:.

Source

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

Dart reverse:.

Source

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

Dart controller:.

Source

pub fn primary(self, primary: bool) -> ListView

Dart primary:.

Source

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

Dart physics:.

Source

pub fn shrink_wrap(self, shrink_wrap: bool) -> ListView

Dart shrinkWrap:.

Source

pub fn cache_extent(self, cache_extent: f64) -> ListView

👎Deprecated:

Use scroll_cache_extent instead.

Dart cacheExtent:.

Source

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

Dart scrollCacheExtent:.

Source

pub fn semantic_child_count(self, semantic_child_count: i32) -> ListView

Dart semanticChildCount:.

Source

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

Dart dragStartBehavior:.

Source

pub fn keyboard_dismiss_behavior( self, keyboard_dismiss_behavior: ScrollViewKeyboardDismissBehavior, ) -> ListView

Dart keyboardDismissBehavior:.

Source

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

Dart restorationId:.

Source

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

Dart clipBehavior:.

Source

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

Dart hitTestBehavior:.

Source

pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> ListView

Dart ListView(padding:).

Source

pub fn item_extent(self, item_extent: f64) -> ListView

Dart ListView(itemExtent:).

Source

pub fn item_extent_builder( self, item_extent_builder: ItemExtentBuilder, ) -> ListView

Dart ListView(itemExtentBuilder:).

Source

pub fn prototype_item<K>(self, prototype_item: impl IntoWidget<K>) -> ListView

Dart ListView(prototypeItem:).

Source

pub fn children(self, children: impl IntoIterator<Item = WidgetRef>) -> ListView

Dart children:.

The children also fill in ScrollViewData::semantic_child_count while it still holds the constructor’s default, as Dart’s semanticChildCount ?? children.length does.

Source

pub fn add_automatic_keep_alives(self, value: bool) -> ListView

Dart addAutomaticKeepAlives: on a constructor that takes children.

Source

pub fn add_repaint_boundaries(self, value: bool) -> ListView

Dart addRepaintBoundaries: on a constructor that takes children.

Source

pub fn add_semantic_indexes(self, value: bool) -> ListView

Dart addSemanticIndexes: on a constructor that takes children.

Trait Implementations§

Source§

impl BoxScrollView for ListView

Source§

fn box_scroll_view_data(&self) -> &BoxScrollViewData

Source§

fn box_scroll_view_data_mut(&mut self) -> &mut BoxScrollViewData

The BoxScrollViewData bag, mutably.
Source§

fn build_child_layout( &self, _app: &mut App, _context: BuildContext, ) -> WidgetRef

Implementors override this method to build the layout model.
Source§

impl Clone for ListView

Source§

fn clone(&self) -> ListView

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ListView

Source§

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

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

impl Default for ListView

Source§

fn default() -> ListView

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

impl ScrollView for ListView

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. Read more
Source§

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

Returns the AxisDirection in which the scroll view scrolls. Read more
Source§

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

Build the viewport. Read more
Source§

impl StatelessWidget for ListView

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 build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
Source§

fn debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

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

Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget answers with itself, which is what a parent asking an erased child for its preferred size reads.

Auto Trait Implementations§

§

impl !RefUnwindSafe for ListView

§

impl !Send for ListView

§

impl !Sync for ListView

§

impl !UnwindSafe for ListView

§

impl Forget for ListView

§

impl Freeze for ListView
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 ScrollBehavior> is !null: Freeze, PhantomData<RcInner<dyn ScrollBehavior>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Fn(i32, SliverLayoutDimensions) -> Option<f64>> is !null: Freeze, PhantomData<RcInner<dyn Fn(i32, SliverLayoutDimensions) -> Option<f64>>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const RcInner<dyn SliverChildDelegate> is !null: Freeze, PhantomData<RcInner<dyn SliverChildDelegate>>: Freeze, PhantomData<Rc<dyn Widget>>: Freeze,

§

impl Move for ListView

§

impl Unpin for ListView
where Rc<dyn Key>: Unpin, NonZero<u32>: Unpin, &'static ScrollControllerVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn ScrollPhysics>: Unpin, Rc<dyn ScrollBehavior>: Unpin, *const u8 is !null: Unpin, Rc<dyn Fn(i32, SliverLayoutDimensions) -> Option<f64>>: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn SliverChildDelegate>: Unpin,

§

impl UnsafeUnpin for ListView
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 ScrollBehavior> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ScrollBehavior>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Fn(i32, SliverLayoutDimensions) -> Option<f64>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(i32, SliverLayoutDimensions) -> Option<f64>>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn SliverChildDelegate> is !null: UnsafeUnpin, PhantomData<RcInner<dyn SliverChildDelegate>>: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<StatelessKind> for W
where W: StatelessWidget,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>