Masonry Grid

Loading preview

Starting the Flutter app

Pinterest-style staggered grid with varying heights

Get the source

Add it to your project

Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.

First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.

How it works

Items go to the shortest column: LayoutBuilder walks _items, tracking estimated heights and collecting indexes in columns. Each column is a Column inside a Row with spacing, so horizontal and vertical gaps match. _MasonryCard sizes to its content rather than a fixed height, which leaves room for the title at any text size. Everything builds eagerly inside a SingleChildScrollView, and crossAxisCount is fixed at two.

Adapting it

  • Derive crossAxisCount from constraints.maxWidth for wider screens.
  • Swap the colored block for images with known aspect ratios.
  • Use flutter_staggered_grid_view to lazily build long lists.