flutter
staggered grid view
a flutter staggered grid view which supports multiple columns with rows of varying sizes.
![[2025] Flutter #1 Staggered Grid View staggered grid view](https://i0.wp.com/flutterawesome.com/content/images/2018/09/flutter_staggered_grid_view.png?w=770&ssl=1)
features
- configurable cross-axis count or max cross-axis extent like the gridview
- tiles can have a fixed main-axis extent, or a multiple of the cell’s length.
- configurable main-axis and cross-axis margins between tiles.
- sliverstaggeredgrid for using in a customscrollview.
- staggered and spannable grid layouts.
![[2025] Flutter #1 Staggered Grid View spannable_1](https://i0.wp.com/flutterawesome.com/content/images/2018/09/spannable_1.gif?w=770&ssl=1)
![[2025] Flutter #1 Staggered Grid View staggered_1](https://i0.wp.com/flutterawesome.com/content/images/2018/09/staggered_1.gif?w=770&ssl=1)
- tiles can fit the content in the main axis.
![[2025] Flutter #1 Staggered Grid View dynamic_tile_sizes](https://i0.wp.com/flutterawesome.com/content/images/2018/09/dynamic_tile_sizes.gif?w=770&ssl=1)
getting started
in the pubspec.yaml
of your flutter project, add the following dependency:
dependencies:
...
flutter_staggered_grid_view: "^0.2.2"
in your library add the following import:
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
for help getting started with flutter, view the online documentation.
example
![[2025] Flutter #1 Staggered Grid View screenshot_example](https://i0.wp.com/raw.githubusercontent.com/letsar/flutter_staggered_grid_view/master/doc/images/example_02.png?w=770&ssl=1)
new staggeredgridview.countbuilder(
crossaxiscount: 4,
itemcount: 8,
itembuilder: (buildcontext context, int index) => new container(
color: colors.green,
child: new center(
child: new circleavatar(
backgroundcolor: colors.white,
child: new text('$index'),
),
)),
staggeredtilebuilder: (int index) =>
new staggeredtile.count(2, index.iseven ? 2 : 1),
mainaxisspacing: 4.0,
crossaxisspacing: 4.0,
)
you can find more examples in the example project.
constructors
the staggeredgridview
follow the same constructors convention than the gridview.
there are two more constructors: countbuilder
and extentbuilder
. these constructors allow you to define a builder for the layout and a builder for the children.
tiles
a staggeredgridview needs to know how to display each tile, and what widget is associated with a tile.
a tile needs to have a fixed number of cell to occupy in the cross axis.
for the extent in the main axis you have 3 options:
- you want a fixed number of cells => use
staggeredtile.count
. - you want a fixed extent => use
staggeredtile.extent
. - you want a variable extent, defined by the content of the tile itself => use
staggeredtile.fit
.
Comments are closed.