why use Gridview.builder not Gridview.count?

Gridview.builder not Gridview.count

Gridview.builder vs Gridview.count

So what is the difference between these two widgets, if they all return grid view with its cells?

It’s the same in the final result, both you will get a grid view, and both of them how grid view with its cells, but really what makes them different from each other.


we use it every time to build a grid view and especially when you know how many cells you want to show in the grid, how many items will be in the view of your app, you can use this widget if you building a small grid view with a small number of items, because in this method of creating a grid flutter will render all the items that you add in the children of the GridView.count, and let's say you have 1000 item in the grid!!
of course, you will say goodbye to the performance.


But in the case of using GridView.builder, you can use it when you don’t know how many items you will show in the view.
It only renders the items on the screen by its auto-generated index, which determines each element of the grid items, and does not render the items that are not on the screen.
And this is great for performance when you have a lot of items in your grid view.

itemCount: this is to inform the gridview how many items will be in the grid.

itemBuilder: Which is a function that receives or has inputs (context, and the index of the item that will build a girl cell for it) and this returns the widget that we want to display on the grid, will build every cell of this grid with items data which you will show in the GridTile.

gridDelegate: Define how your cell looks like, how your grid will be structured, how many columns you will have, the high and width of the cell and so on.


GridView.builder creates widgets on demand and is used when grid items are a large or infinite number of grid items.

GridView.count creates a grid view with a fixed number of tiles

Use GridView.builder when you have a large number of widgets to get better performance. also using gridDelegate gives you more control over UI.

⭐⭐⭐  Buy Food for my Dog 🐶 ⭐⭐⭐



#buttons=(Accept !) #days=(14)

Our website uses cookies to enhance your experience. Learn More
Accept !