Learn/Core Widgets/ListView & GridView

ListView & GridView

Display scrollable lists and grids

6 min~5 min read+35 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. ListTile Widget
  2. 2. Horizontal Scrolling
  3. 3. List And Grid Performance Mindset
  4. 4. This Lesson In Simple Words
  5. 5. Your level focus
  6. 6. One practical habit
  7. 7. Deep Understanding Guide
  8. 8. Why this lesson matters
  9. 9. Study flow for better retention
  10. 10. Quick Glossary

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

ListView

ListView is the go-to widget for displaying scrollable lists of content in Flutter. There are three main ways to create a ListView, each suited for different use cases.

dart
1// 1. ListView with children (for small, fixed lists)
2ListView(
3 children: [
4 ListTile(title: Text('Item 1')),
5 ListTile(title: Text('Item 2')),
6 ListTile(title: Text('Item 3')),
7 ],
8)
9
10// 2. ListView.builder (for large/dynamic lists - RECOMMENDED)
11ListView.builder(
12 itemCount: items.length,
13 itemBuilder: (context, index) {
14 return ListTile(
15 title: Text(items[index]),
16 );
17 },
18)
19
20// 3. ListView.separated (with dividers)
21ListView.separated(
22 itemCount: items.length,
23 itemBuilder: (context, index) => ListTile(title: Text(items[index])),
24 separatorBuilder: (context, index) => Divider(),
25)

Always Use ListView.builder

💡 Always Use ListView.builder

For lists with many items, the .builder constructor only creates the widgets that are currently visible on screen. This saves memory and significantly improves scrolling performance.

ListTile Widget

ListTile is a pre-built convenience widget designed specifically for list items. It provides a consistent layout with leading, title, subtitle, and trailing slots.

dart
1ListTile(
2 leading: CircleAvatar(child: Text('A')),
3 title: Text('Title'),
4 subtitle: Text('Subtitle'),
5 trailing: Icon(Icons.arrow_forward),
6 onTap: () {
7 print('Tapped!');
8 },
9)

GridView

GridView displays items in a two-dimensional grid layout. It is perfect for image galleries, product catalogs, and any content that benefits from a grid arrangement.

dart
1// Fixed column count
2GridView.count(
3 crossAxisCount: 2, // 2 columns
4 children: [
5 Container(color: Colors.red),
6 Container(color: Colors.blue),
7 Container(color: Colors.green),
8 Container(color: Colors.yellow),
9 ],
10)
11
12// GridView.builder (for large lists)
13GridView.builder(
14 gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
15 crossAxisCount: 3,
16 crossAxisSpacing: 10,
17 mainAxisSpacing: 10,
18 childAspectRatio: 1, // width/height ratio
19 ),
20 itemCount: products.length,
21 itemBuilder: (context, index) {
22 return ProductCard(products[index]);
23 },
24)

Horizontal Scrolling

By default, ListView scrolls vertically. You can change the scroll direction to horizontal by setting the scrollDirection property. This is commonly used for horizontal carousels and category chips.

dart
1// Horizontal ListView
2ListView.builder(
3 scrollDirection: Axis.horizontal,
4 itemCount: items.length,
5 itemBuilder: (context, index) {
6 return Container(
7 width: 150,
8 margin: EdgeInsets.all(8),
9 child: Card(child: Center(child: Text(items[index]))),
10 );
11 },
12)
13
14// Note: Wrap in SizedBox or Container with fixed height
15SizedBox(
16 height: 200,
17 child: ListView.builder(
18 scrollDirection: Axis.horizontal,
19 ...
20 ),
21)

List And Grid Performance Mindset

Use lazy builders for dynamic collections by default.

For each collection screen, define:

  • loading skeleton or spinner state
  • empty state with helpful message
  • error state with retry option
  • success state with smooth scrolling

High-quality list screens are not only about rendering items. They are about complete data-state handling.

Scrollable UI Checklist

  • Using ListView.builder or GridView.builder for large data.
  • Item widgets are lightweight and reusable.
  • Scroll direction and container constraints are explicit.
  • Empty and error states are user-friendly and actionable.

This Lesson In Simple Words

Display scrollable lists and grids. Widgets are reusable UI blocks. You combine them like LEGO pieces to build screens.

Your level focus

Build confidence with basics first; speed comes later.

One practical habit

Sketch the widget tree first, then code from top to bottom.

Deep Understanding Guide

Why this lesson matters

Most Flutter productivity comes from understanding layout rules and composing widgets cleanly.

Study flow for better retention

  1. Read one section, run one tiny example, then explain the idea in your own words.
  2. When a UI bug appears, inspect constraints and parent-child relations before changing random values.
  3. If you can teach it in 45 seconds without notes, you understood it.

Common Mistakes To Avoid

  • Nesting too many widgets without extracting reusable pieces.
  • Ignoring constraints and guessing with random SizedBox heights.
  • Using one giant build method for unrelated UI sections.
  • Putting heavy calculations directly in build methods.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one card layout with Row/Column and rebuild it using Stack for comparison.
  • Split a large widget into 3 smaller widgets with clear responsibilities.
  • Use const constructors where possible and observe rebuild behavior.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "Why use ListView.builder instead of ListView?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • state: Data that can change and update what the user sees.
  • build: The method that describes UI for the current state.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Lesson Completion Checklist

  • I can explain "ListView & GridView" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Nesting too many widgets without extracting reusable pieces.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

Why use ListView.builder instead of ListView?

ListView.builder lazily builds items as they scroll into view.

What does crossAxisCount: 3 mean in GridView?

crossAxisCount sets the number of columns in a vertical GridView.

How do you make ListView scroll horizontally?

scrollDirection property controls scroll direction.

ListTile's leading property is for:

leading is the widget before the title, trailing is after.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue