Chapters

Hide chapters

Flutter Apprentice

Fourth Edition · Flutter 3.16.9 · Dart 3.2.6 · Android Studio 2023.1.1

Section II: Everything’s a Widget

Section 2: 5 chapters
Show chapters Hide chapters

Section IV: Networking, Persistence & State

Section 4: 6 chapters
Show chapters Hide chapters

5. Scrollable Widgets
Written by Vincent Ngo

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Building scrollable content is an essential part of UI development. There’s only so much information a user can process at a time, let alone fit on an entire screen in the palm of your hand!

In this chapter, you’ll learn everything you need to know about scrollable widgets. In particular, you’ll learn:

  • How to use ListView.
  • How to nest scroll views.

You’ll continue to build the Yummy app by adding HomeScreen, a new view that enables users to explore different restaurants, food categories, and view friends’ posts.

By the end of this chapter, you’ll be a scrollable widget wizard!

Getting Started

Open the starter project in Android Studio, then run flutter pub get if necessary and run the app.

You’ll see a placeholder for each tab as shown below:

Project Files

There are new files in this starter project to help you out. Before you learn how to create scrollable widgets, take a look at them.

Assets Folder

The assets directory contains all the images that you’ll use to build your app.

Sample Images

  • categories: Contains images for food categories.
  • food: Contains sample food items from a restaurant menu.
  • profile_pics: Contains Kodeco team member pictures.
  • restaurants: Contains restaurant hero images.

New Classes

In the lib directory, you’ll also notice the new api folder, as shown below:

API Folder

The api folder contains a mock service class.

Introducing ListView

ListView is a very popular Flutter component. It’s a linear scrollable widget that arranges its children linearly and supports horizontal and vertical scrolling.

Introducing Constructors

A ListView has four constructors:

Setting Up the Explore Screen

The first screen you’ll create is the ExploreScreen. It contains three sections:

Updating the Navigation Pages

In lib/home.dart, locate // TODO: Replace with ExplorePage and replace Center below it with the following:

Creating a FutureBuilder

How do you display your UI with an asynchronous task?

Building Restaurant Section

The first scrollable component you’ll build is RestaurantSection. This is the top section of the ExplorePage. It will be a horizontal list view.

Adding the Restaurant Section

Open explore_page.dart and add the following import:

Nested ListViews

There are two approaches to adding the category and post sections: the Column approach and the nested ListView approach. You’ll take a look at each of them now.

Column Approach

You could put the list views in a Column, that arranges items in a vertical layout. So that makes sense right?

Nested ListView Approach

In the second approach, you nest multiple list views in a parent list view.

Adding a Nested ListView

First, go back to explore_page.dart locate the comment // TODO: Wrap in a ListView and replace it and return RestaurantSection widget with the following:

Building Category Section

The second scrollable component you’ll build is CategorySection. Users will be able to scroll through a list of food categories horizontally.

Adding Category Section

Returning to explore_page.dart, locate // TODO: Add CategorySection and replace it and the Container below it with the following:

Building the Post Section

The third scrollable component you’ll build is PostSection. Users will be able to scroll through a list of friend posts vertically.

Adding Post Section

Go back to explore_page.dart and find // TODO: Add PostSection and replace it and Container with the following:

Other Scrollable Widgets

There are many more scrollable widgets for various use cases. Here are some not covered in this chapter:

Key Points

  • ListView and GridView support both horizontal and vertical scroll directions.
  • The primary property lets Flutter know which scroll view is the primary scroll view.
  • physics in a scroll view lets you change the user scroll interaction.
  • Especially in a nested list view, remember to set shrinkWrap to true so you can give the scroll view a fixed height for all the items in the list.
  • Use a FutureBuilder to wait for an asynchronous task to complete.
  • You can nest scrollable widgets. For example, you can place a grid view within a list view. Unleash your wildest imagination!

Where to Go From Here?

At this point, you’ve learned how to create ListViews. They are much easier to use than iOS’s UITableView and Android’s RecyclerView, right? Building scrollable widgets is an important skill you should master!

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now