Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement in Flutter a staggered grid view?

Tags:

flutter

I would like to implement in Flutter a Staggered Grid view - such as the Pinterest staggered grid view (which used to be implemented via their own Android Widget, and now via the Google's StaggeredGridLayoutManager).

So the requirements are:

  • items are fetched via an API - so I need something similar to the GridView.builder or ListView.builder, so that I can implement an infinite scroll
  • each item to be displayed in the Grid View, is made of:
    • an image - say e.g. a picture
    • some textual/visual information, which comprises: a variable length string (which might span two or more rows), an icon, some other pieces of texts (e.g. money amounts)

I know there is a plugin which is named flutter_staggered_grid_view, but this is of no use because it requires to know in advance the precise height of each tile of the grid - which of course it is not my case.

like image 380
Piercarlo Slavazza Avatar asked May 20 '18 13:05

Piercarlo Slavazza


People also ask

How do you change the grid layout in Flutter?

The simplest way to get started using grids is by using the GridView. count() constructor, because it allows you to specify how many rows or columns you'd like. To visualize how GridView works, generate a list of 100 widgets that display their index in the list.

How do you create a custom grid in Flutter?

Creating GridView In Flutter We can create a grid view in flutter by calling the constructor of GridView class and providing it with required properties. It has one required property which is gridDelegate. It controls the layout of the child widgets of the grid view.


1 Answers

I've updated the flutter_staggered_grid_view package.

Now you can add tiles that fit their content size like this:

tile fit content

You have to create tiles using the StaggeredTile.fit(this.crossAxisCellCount) constructor to do it.

Hope it helps.

like image 148
Romain Rastel Avatar answered Sep 17 '22 19:09

Romain Rastel