CHAPTER 12
Beginner
Flutter Lists and GridView
Updated: May 16, 2026
25 min read
# CHAPTER 12
Flutter Lists and GridView
1. Introduction
If you open Spotify, you see a list of songs. If you open Amazon, you see a grid of products. If you open Twitter, you see a list of tweets. Vertical and horizontal scrolling feeds are the absolute core of modern mobile app design. While a standardColumn stacks items vertically, it has a fatal flaw: it cannot scroll! If items fall off the screen, the app crashes. In this chapter, we will master Flutter Lists and GridView. We will explore the simple ListView, optimize our memory using the incredibly powerful ListView.builder, and create Instagram-style photo galleries using GridView.
2. Learning Objectives
By the end of this chapter, you will be able to:-
Create a basic scrolling list using
ListView.
-
Understand why standard
Columnscannot handle large data.
-
Optimize memory and performance using
ListView.builder.
-
Create a 2-column or 3-column layout using
GridView.count.
-
Combine lists with the
ListTilewidget for standard UI patterns.
3. The Basic ListView
A ListView is essentially a Column that automatically knows how to scroll.
- Use Case: A settings menu with a small, fixed number of items (e.g., 5 options).
dart
4. The Performance Problem
If you have an array of 10,000 products, and you generate 10,000 widgets inside a standardListView, Flutter will render all 10,000 widgets immediately. Your phone will run out of RAM and crash within seconds.
Solution: We only need to render the 6 items currently visible on the glass screen! As the user scrolls, we recycle the widgets. This is called "Lazy Loading."
5. The Champion: ListView.builder
To achieve Lazy Loading, we use ListView.builder. It is the most important layout widget in Flutter.
It takes two crucial properties:
-
1.
itemCount: How many items are in your data list?
-
2.
itemBuilder: A loop function that builds the UI for *one* item at a time, receiving anindex(0, 1, 2, etc.).
dart
6. The ListTile Widget
When building a list (like an email inbox), you usually want an icon on the left, a title, a subtitle, and an arrow on the right.
Do not build this manually with Rows and Columns! Flutter provides the perfect pre-built widget: ListTile.
dart
7. Creating Grids with GridView
If you are building Pinterest or a Photo Gallery, you want items side-by-side. Use GridView.
GridView.count allows you to specify exactly how many columns you want.
dart
*(Note: For massive data, you should use GridView.builder for the exact same memory optimizations as ListView.builder!)*
8. Visual Learning: ListView.builder Memory
txt
9. Common Mistakes
-
Lists inside Columns: If you place a
ListViewinside aColumn, the screen will turn white and crash. A Column tries to let its children be as tall as they want, and a ListView tries to be infinitely tall. This is an impossible math problem for Flutter.
ListView inside an Expanded widget. This tells the ListView: *"Only take up the remaining screen space, then start scrolling."*
10. Best Practices
-
Separators: If you want a thin grey line between your list items, don't build it manually. Use
ListView.separated. It takes a third parameter calledseparatorBuilderwhere you can simply return aDivider()widget!
11. Mini Project: Build a Contact List
Objective: UseListView.builder and ListTile to build a dynamic address book.
-
1.
Create a
StatelessWidget.
-
2.
Inside
build, define a list of 10 fake names.
-
3.
Return a
Scaffoldwith anAppBar.
-
4.
In the
body, return aListView.builder.
-
5.
Set the
itemCountto the length of your names list.
-
6.
In the
itemBuilder, return aListTile.
-
7.
Set the
leadingto aCircleAvatarcontaining the first letter of the name!
-
8.
Set the
titleto the full name.
- 9. Press Play and enjoy your beautiful, memory-optimized, scrolling contact list.
12. Practice Exercises
- 1. What pre-built widget perfectly formats an icon, a title, a subtitle, and a trailing arrow into a standardized list item row?
-
2.
Why is wrapping a
ListViewinside anExpandedwidget necessary when it is placed inside aColumn?
13. MCQs with Answers
Question 1
Why is ListView.builder strongly preferred over a standard ListView when rendering an Amazon search result containing 5,000 products?
Question 2
You want to display a photo gallery with exactly 3 images per row. Which widget should you use?
14. Interview Questions
-
Q: Explain the mechanical and memory differences between
ListViewandListView.builder.
-
Q: Describe the "Infinite Height" layout error that occurs when a
ListViewis placed directly inside aColumn. What is the architectural solution?
-
Q: Explain the purpose of the
itemBuilderfunction parameter in aListView.builder. What are the two arguments it receives, and how are they used?
15. FAQs
Q: How do I make a ListView scroll horizontally instead of vertically? A: Inside theListView, just add scrollDirection: Axis.horizontal!
16. Summary
In Chapter 12, we mastered dynamic, scrolling layouts. We learned that while a basicListView is fine for small static menus, professional apps demand the RAM optimization of ListView.builder, which dynamically recycles widgets as they scroll on and off the screen. We streamlined our UI code by utilizing the incredibly versatile ListTile, and we explored GridView to create multi-column image layouts.