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:
-
ListView::newtakes an explicit list of children through thechildrensetter. 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. -
ListView::buildertakes 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. -
ListView::separatedtakes two builders:item_builderbuilds child items on demand, andseparator_buildersimilarly builds separator children which appear in between the child items. This is appropriate for list views with a fixed number of children. -
ListView::customtakes aSliverChildDelegateRef, 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_extentproperty, which allows forcing the children’s extent to a given value. - The
item_extent_builderproperty, which allows forcing the children’s extent to be the value returned by the callback.
children_delegate: SliverChildDelegateRefA delegate that provides the children for the ListView.
The SliverList::delegate property corresponds to this one.
Implementations§
Source§impl ListView
impl ListView
Sourcepub fn new() -> ListView
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.
Sourcepub fn builder(
item_builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static,
) -> ListViewBuilder
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.
Sourcepub 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
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).
Sourcepub fn custom(children_delegate: SliverChildDelegateRef) -> ListView
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.
Sourcepub fn scroll_direction(self, scroll_direction: Axis) -> ListView
pub fn scroll_direction(self, scroll_direction: Axis) -> ListView
Dart scrollDirection:.
Sourcepub fn controller(self, controller: ScrollControllerRef) -> ListView
pub fn controller(self, controller: ScrollControllerRef) -> ListView
Dart controller:.
Sourcepub fn physics(self, physics: ScrollPhysicsRef) -> ListView
pub fn physics(self, physics: ScrollPhysicsRef) -> ListView
Dart physics:.
Sourcepub fn shrink_wrap(self, shrink_wrap: bool) -> ListView
pub fn shrink_wrap(self, shrink_wrap: bool) -> ListView
Dart shrinkWrap:.
Sourcepub fn cache_extent(self, cache_extent: f64) -> ListView
👎Deprecated: Use scroll_cache_extent instead.
pub fn cache_extent(self, cache_extent: f64) -> ListView
Use scroll_cache_extent instead.
Dart cacheExtent:.
Sourcepub fn scroll_cache_extent(
self,
scroll_cache_extent: ScrollCacheExtent,
) -> ListView
pub fn scroll_cache_extent( self, scroll_cache_extent: ScrollCacheExtent, ) -> ListView
Dart scrollCacheExtent:.
Sourcepub fn semantic_child_count(self, semantic_child_count: i32) -> ListView
pub fn semantic_child_count(self, semantic_child_count: i32) -> ListView
Dart semanticChildCount:.
Sourcepub fn drag_start_behavior(
self,
drag_start_behavior: DragStartBehavior,
) -> ListView
pub fn drag_start_behavior( self, drag_start_behavior: DragStartBehavior, ) -> ListView
Dart dragStartBehavior:.
Sourcepub fn keyboard_dismiss_behavior(
self,
keyboard_dismiss_behavior: ScrollViewKeyboardDismissBehavior,
) -> ListView
pub fn keyboard_dismiss_behavior( self, keyboard_dismiss_behavior: ScrollViewKeyboardDismissBehavior, ) -> ListView
Dart keyboardDismissBehavior:.
Sourcepub fn restoration_id(self, restoration_id: impl Into<String>) -> ListView
pub fn restoration_id(self, restoration_id: impl Into<String>) -> ListView
Dart restorationId:.
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> ListView
pub fn clip_behavior(self, clip_behavior: Clip) -> ListView
Dart clipBehavior:.
Sourcepub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> ListView
pub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> ListView
Dart hitTestBehavior:.
Sourcepub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> ListView
pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> ListView
Dart ListView(padding:).
Sourcepub fn item_extent(self, item_extent: f64) -> ListView
pub fn item_extent(self, item_extent: f64) -> ListView
Dart ListView(itemExtent:).
Sourcepub fn item_extent_builder(
self,
item_extent_builder: ItemExtentBuilder,
) -> ListView
pub fn item_extent_builder( self, item_extent_builder: ItemExtentBuilder, ) -> ListView
Dart ListView(itemExtentBuilder:).
Sourcepub fn prototype_item<K>(self, prototype_item: impl IntoWidget<K>) -> ListView
pub fn prototype_item<K>(self, prototype_item: impl IntoWidget<K>) -> ListView
Dart ListView(prototypeItem:).
Sourcepub fn children(self, children: impl IntoIterator<Item = WidgetRef>) -> ListView
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.
Sourcepub fn add_automatic_keep_alives(self, value: bool) -> ListView
pub fn add_automatic_keep_alives(self, value: bool) -> ListView
Dart addAutomaticKeepAlives: on a constructor that takes children.
Sourcepub fn add_repaint_boundaries(self, value: bool) -> ListView
pub fn add_repaint_boundaries(self, value: bool) -> ListView
Dart addRepaintBoundaries: on a constructor that takes children.
Sourcepub fn add_semantic_indexes(self, value: bool) -> ListView
pub fn add_semantic_indexes(self, value: bool) -> ListView
Dart addSemanticIndexes: on a constructor that takes children.
Trait Implementations§
Source§impl BoxScrollView for ListView
impl BoxScrollView for ListView
Source§fn box_scroll_view_data(&self) -> &BoxScrollViewData
fn box_scroll_view_data(&self) -> &BoxScrollViewData
BoxScrollViewData bag
(box_scroll_view_accessors!).Source§fn box_scroll_view_data_mut(&mut self) -> &mut BoxScrollViewData
fn box_scroll_view_data_mut(&mut self) -> &mut BoxScrollViewData
BoxScrollViewData bag, mutably.Source§fn build_child_layout(
&self,
_app: &mut App,
_context: BuildContext,
) -> WidgetRef
fn build_child_layout( &self, _app: &mut App, _context: BuildContext, ) -> WidgetRef
Source§impl ScrollView for ListView
impl ScrollView for ListView
Source§fn scroll_view_data(&self) -> &ScrollViewData
fn scroll_view_data(&self) -> &ScrollViewData
ScrollViewData bag (scroll_view_accessors!).Source§fn scroll_view_data_mut(&mut self) -> &mut ScrollViewData
fn scroll_view_data_mut(&mut self) -> &mut ScrollViewData
ScrollViewData bag, mutably.Source§fn build_slivers(&self, app: &mut App, context: BuildContext) -> Vec<WidgetRef>
fn build_slivers(&self, app: &mut App, context: BuildContext) -> Vec<WidgetRef>
Source§fn get_direction(&self, app: &mut App, context: BuildContext) -> AxisDirection
fn get_direction(&self, app: &mut App, context: BuildContext) -> AxisDirection
AxisDirection in which the scroll view scrolls. Read moreSource§fn build_viewport(
&self,
app: &mut App,
context: BuildContext,
offset: ViewportOffsetRef,
axis_direction: AxisDirection,
slivers: Vec<WidgetRef>,
) -> WidgetRef
fn build_viewport( &self, app: &mut App, context: BuildContext, offset: ViewportOffsetRef, axis_direction: AxisDirection, slivers: Vec<WidgetRef>, ) -> WidgetRef
Source§impl StatelessWidget for ListView
impl StatelessWidget for ListView
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 build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
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 ListViewwhere
*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 ListViewwhere
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 ListViewwhere
*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> 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.