Skip to main content

GridView

Struct GridView 

Source
pub struct GridView {
    pub grid_delegate: Rc<dyn SliverGridDelegate>,
    pub children_delegate: SliverChildDelegateRef,
    /* private fields */
}
Expand description

A scrollable, 2D array of widgets.

The main axis direction of a grid is the direction in which it scrolls (the ScrollViewData::scroll_direction).

The most commonly used grid layouts are GridView::count, which creates a layout with a fixed number of tiles in the cross axis, and GridView::extent, which creates a layout with tiles that have a maximum cross-axis extent. A custom SliverGridDelegate can produce an arbitrary 2D arrangement of children, including arrangements that are unaligned or overlapping.

To create a grid with a large (or infinite) number of children, use the GridView::builder constructor with either a SliverGridDelegateWithFixedCrossAxisCount or a SliverGridDelegateWithMaxCrossAxisExtent for the grid delegate.

To use a custom SliverChildDelegate, use GridView::custom.

To create a linear array of children, use a ListView.

To control the initial scroll offset of the scroll view, provide a controller with its ScrollController::initial_scroll_offset property set.

§Transitioning to CustomScrollView

A GridView is basically a CustomScrollView with a single SliverGrid in its CustomScrollView::slivers property.

By default, GridView will automatically pad the limits of the grid’s scrollable to avoid partial obstructions indicated by MediaQuery’s padding. To avoid this behavior, override with a zero padding property.

Fields§

§grid_delegate: Rc<dyn SliverGridDelegate>

A delegate that controls the layout of the children within the GridView.

The GridView::new, GridView::builder, and GridView::custom constructors let you specify this delegate explicitly. The other constructors create a grid_delegate implicitly.

§children_delegate: SliverChildDelegateRef

A delegate that provides the children for the GridView.

The GridView::custom constructor lets you specify this delegate explicitly. The other constructors create a children_delegate that wraps the given child list.

Implementations§

Source§

impl GridView

Source

pub fn new(grid_delegate: Rc<dyn SliverGridDelegate>) -> GridView

Creates a scrollable, 2D array of widgets with a custom SliverGridDelegate, from an explicit list of children that the children setter supplies.

Source

pub fn builder( grid_delegate: Rc<dyn SliverGridDelegate>, item_builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static, ) -> GridViewBuilder

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

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

Providing a non-None item_count improves the ability of the GridView to estimate 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( grid_delegate: Rc<dyn SliverGridDelegate>, children_delegate: SliverChildDelegateRef, ) -> GridView

Creates a scrollable, 2D array of widgets with both a custom SliverGridDelegate and a custom SliverChildDelegate.

To use an item builder callback to build children, either use a SliverChildBuilderDelegate or use the GridView::builder constructor.

Source

pub fn count(cross_axis_count: i32) -> GridViewCount

Creates a scrollable, 2D array of widgets with a fixed number of tiles in the cross axis.

Uses a SliverGridDelegateWithFixedCrossAxisCount as the grid_delegate.

See also:

Source

pub fn extent(max_cross_axis_extent: f64) -> GridViewExtent

Creates a scrollable, 2D array of widgets with tiles that each have a maximum cross-axis extent.

Uses a SliverGridDelegateWithMaxCrossAxisExtent as the grid_delegate.

See also:

Source

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

Dart key:.

Source

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

Dart scrollDirection:.

Source

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

Dart reverse:.

Source

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

Dart controller:.

Source

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

Dart primary:.

Source

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

Dart physics:.

Source

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

Dart shrinkWrap:.

Source

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

👎Deprecated:

Use scroll_cache_extent instead.

Dart cacheExtent:.

Source

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

Dart scrollCacheExtent:.

Source

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

Dart semanticChildCount:.

Source

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

Dart dragStartBehavior:.

Source

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

Dart keyboardDismissBehavior:.

Source

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

Dart restorationId:.

Source

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

Dart clipBehavior:.

Source

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

Dart hitTestBehavior:.

Source

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

Dart GridView(padding:).

Source

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

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) -> GridView

Dart addAutomaticKeepAlives: on a constructor that takes children.

Source

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

Dart addRepaintBoundaries: on a constructor that takes children.

Source

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

Dart addSemanticIndexes: on a constructor that takes children.

Trait Implementations§

Source§

impl BoxScrollView for GridView

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 GridView

Source§

fn clone(&self) -> GridView

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 GridView

Source§

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

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

impl ScrollView for GridView

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 GridView

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 GridView

§

impl !Send for GridView

§

impl !Sync for GridView

§

impl !UnwindSafe for GridView

§

impl Forget for GridView

§

impl Freeze for GridView
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 SliverGridDelegate> is !null: Freeze, PhantomData<RcInner<dyn SliverGridDelegate>>: Freeze, *const RcInner<dyn SliverChildDelegate> is !null: Freeze, PhantomData<RcInner<dyn SliverChildDelegate>>: Freeze, PhantomData<Rc<dyn Widget>>: Freeze,

§

impl Move for GridView

§

impl Unpin for GridView
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 SliverGridDelegate>: Unpin, Rc<dyn SliverChildDelegate>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for GridView
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 SliverGridDelegate> is !null: UnsafeUnpin, PhantomData<RcInner<dyn SliverGridDelegate>>: 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>