Grid View
Grid View
What is GridView?
GridView is a scrollable widget in Flutter that displays children in a 2D grid format (rows and
columns). It’s commonly used for layouts where items need to be displayed side-by-side, such
as:
Image galleries
Student or user cards
Product listings
Icon menus
Example:
1. Define a List of Colors
final List<Color> colors = [
Colors.red,
Colors.green,
Colors.blue,
Colors.orange,
Colors.purple,
Colors.teal,
];
A list of 6 colors that will be used as background colors for each grid item.
� 2. GridView.builder
child: GridView.builder(
GridView.builder is used for dynamically building grid items on demand for better
performance.
Tells the grid to generate as many items as there are in the colors list (6 items).
A function that builds each individual grid item based on the index.
Creates a colored Container for each grid tile using the color from the colors list.
Places a Text widget inside the container, centered both horizontally and vertically.
Displays text like "Item 1", "Item 2", ..., "Item 6".
Text is white with font size 18.