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: SliverChildDelegateRefA 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
impl GridView
Sourcepub fn new(grid_delegate: Rc<dyn SliverGridDelegate>) -> GridView
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.
Sourcepub fn builder(
grid_delegate: Rc<dyn SliverGridDelegate>,
item_builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static,
) -> GridViewBuilder
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.
Sourcepub fn custom(
grid_delegate: Rc<dyn SliverGridDelegate>,
children_delegate: SliverChildDelegateRef,
) -> GridView
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.
Sourcepub fn count(cross_axis_count: i32) -> GridViewCount
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:
SliverGrid::count, the equivalent constructor forSliverGrid.
Sourcepub fn extent(max_cross_axis_extent: f64) -> GridViewExtent
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:
SliverGrid::extent, the equivalent constructor forSliverGrid.
Sourcepub fn scroll_direction(self, scroll_direction: Axis) -> GridView
pub fn scroll_direction(self, scroll_direction: Axis) -> GridView
Dart scrollDirection:.
Sourcepub fn controller(self, controller: ScrollControllerRef) -> GridView
pub fn controller(self, controller: ScrollControllerRef) -> GridView
Dart controller:.
Sourcepub fn physics(self, physics: ScrollPhysicsRef) -> GridView
pub fn physics(self, physics: ScrollPhysicsRef) -> GridView
Dart physics:.
Sourcepub fn shrink_wrap(self, shrink_wrap: bool) -> GridView
pub fn shrink_wrap(self, shrink_wrap: bool) -> GridView
Dart shrinkWrap:.
Sourcepub fn cache_extent(self, cache_extent: f64) -> GridView
👎Deprecated: Use scroll_cache_extent instead.
pub fn cache_extent(self, cache_extent: f64) -> GridView
Use scroll_cache_extent instead.
Dart cacheExtent:.
Sourcepub fn scroll_cache_extent(
self,
scroll_cache_extent: ScrollCacheExtent,
) -> GridView
pub fn scroll_cache_extent( self, scroll_cache_extent: ScrollCacheExtent, ) -> GridView
Dart scrollCacheExtent:.
Sourcepub fn semantic_child_count(self, semantic_child_count: i32) -> GridView
pub fn semantic_child_count(self, semantic_child_count: i32) -> GridView
Dart semanticChildCount:.
Sourcepub fn drag_start_behavior(
self,
drag_start_behavior: DragStartBehavior,
) -> GridView
pub fn drag_start_behavior( self, drag_start_behavior: DragStartBehavior, ) -> GridView
Dart dragStartBehavior:.
Sourcepub fn keyboard_dismiss_behavior(
self,
keyboard_dismiss_behavior: ScrollViewKeyboardDismissBehavior,
) -> GridView
pub fn keyboard_dismiss_behavior( self, keyboard_dismiss_behavior: ScrollViewKeyboardDismissBehavior, ) -> GridView
Dart keyboardDismissBehavior:.
Sourcepub fn restoration_id(self, restoration_id: impl Into<String>) -> GridView
pub fn restoration_id(self, restoration_id: impl Into<String>) -> GridView
Dart restorationId:.
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> GridView
pub fn clip_behavior(self, clip_behavior: Clip) -> GridView
Dart clipBehavior:.
Sourcepub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> GridView
pub fn hit_test_behavior(self, hit_test_behavior: HitTestBehavior) -> GridView
Dart hitTestBehavior:.
Sourcepub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> GridView
pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> GridView
Dart GridView(padding:).
Sourcepub fn children(self, children: impl IntoIterator<Item = WidgetRef>) -> GridView
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.
Sourcepub fn add_automatic_keep_alives(self, value: bool) -> GridView
pub fn add_automatic_keep_alives(self, value: bool) -> GridView
Dart addAutomaticKeepAlives: on a constructor that takes children.
Sourcepub fn add_repaint_boundaries(self, value: bool) -> GridView
pub fn add_repaint_boundaries(self, value: bool) -> GridView
Dart addRepaintBoundaries: on a constructor that takes children.
Sourcepub fn add_semantic_indexes(self, value: bool) -> GridView
pub fn add_semantic_indexes(self, value: bool) -> GridView
Dart addSemanticIndexes: on a constructor that takes children.
Trait Implementations§
Source§impl BoxScrollView for GridView
impl BoxScrollView for GridView
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 GridView
impl ScrollView for GridView
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 GridView
impl StatelessWidget for GridView
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 GridView
impl !Send for GridView
impl !Sync for GridView
impl !UnwindSafe for GridView
impl Forget for GridView
impl Freeze for GridViewwhere
*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
impl UnsafeUnpin for GridViewwhere
*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> 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.