Skip to main content

GridView

The GridView widget is a scrollable list widget that arranges items in a grid.
Use it to repeat equally sized cells across multiple columns.

Definition and role

The GridView widget is an iterator widget that repeats one item template to draw a grid. Cells are laid out at a uniform size, and you set the number of columns either by how many cells fit in a row or by the maximum size of a single cell. Scroll direction, spacing, and cell ratio are all configurable.

  • Category: Layouts
  • Size on drop: 300 x 200 by default inside a parent layout such as Row, Column, or Stack. Dropped at the top level with no parent, it renders larger to fill the canvas.

Features

FeatureDescription
Grid layoutArranges items in a grid of several columns. Choose how the column count is determined with crossAxisType.
Column count and cell sizeWhen crossAxisType is count, the cells per row (crossAxisCount) determine the column count; when it is extent, the maximum cell size (maxCrossAxisExtent) does.
Spacing and ratioAdjust the cell spacing along the main and cross axes (mainAxisSpacing, crossAxisSpacing) and the width-to-height ratio of a cell (childAspectRatio).
ScrollingSet the scroll direction (scrollDirection), reversed order (reverse), scroll physics (physics), and more.
Script controlAdd and remove items, scroll to a specific item, and handle selection events from a script.

How to use

  1. Open the Layouts category in the left widget palette.
  2. Drag and drop the GridView item onto the canvas.
  3. In the Properties panel on the right, choose crossAxisType. For count, set crossAxisCount (cells per row); for extent, set maxCrossAxisExtent (maximum cell size).
  4. Tune the cell ratio and spacing with childAspectRatio, mainAxisSpacing, and crossAxisSpacing.
  5. Place the item template you want to repeat inside the GridView.

Properties

PropertyDescriptionDefaultValues / type
crossAxisTypeHow the column count is determined — by cell count or by maximum cell sizecountcount, extent
crossAxisCountNumber of cells per row (used when crossAxisType is count)2Number (integer, minimum 1)
maxCrossAxisExtentMaximum cross-axis size of a single cell (used when crossAxisType is extent)100Number
scrollDirectionScroll directionverticalhorizontal, vertical
reverseWhether to reverse the scroll directionfalseTrue / false
controllerScroll controllerNot setScroll controller
primaryWhether to use the primary scroll viewNot setTrue / false
physicsScroll physicsNot setbouncing, clamping, alwaysScrollable, rangeMaintaining, neverScrollable, page
shrinkWrapWhether to shrink to fit the content sizetrueTrue / false
paddingInner paddingNot setPadding value
mainAxisSpacingCell spacing along the main (scroll) axis0Number (minimum 0)
crossAxisSpacingCell spacing along the cross axis0Number (minimum 0)
childAspectRatioWidth-to-height ratio of a cell2Number (minimum 0.1)
addAutomaticKeepAlivesWhether to keep the state of items scrolled off screentrueTrue / false
addRepaintBoundariesWhether to add repaint boundariestrueTrue / false
addSemanticIndexesWhether to add semantic indexestrueTrue / false
cacheExtentSize of the area rendered ahead into the cacheNot setNumber
semanticChildCountNumber of semantic childrenNot setNumber (integer)
dragStartBehaviorHow the start of a drag is detectedstartdown, start
keyboardDismissBehaviorHow the keyboard is dismissed while scrollingmanualmanual, onDrag
restorationIdID used to restore the scroll positionNot setString
clipBehaviorHow content outside the bounds is clippedhardEdgenone, hardEdge, antiAlias, antiAliasWithSaveLayer
itemCountNumber of items to repeat0Number (integer)

Notes and tips

tip

Set crossAxisType to count and crossAxisCount drives the column count; set it to extent and maxCrossAxisExtent does. Change crossAxisType in the editor and the unused property is hidden automatically.

warning

Setting controller while primary is true is treated as an error, because the two cannot be used together. Use only one of them.

Learn more

tip

For the full set of Widget Control members (Property, Method, Event) that drive this widget from a script, see GridView Widget Control.