FlutterBasic 2 min read

Flutter ListView.builder and efficient scrolling lists

Build visible list items on demand, keep state out of temporary row instances and provide stable item identities.

On this page

ListView.builder creates children as needed rather than constructing every row widget in advance. This is useful for a long or dynamic collection, but it does not by itself fetch data lazily from a server.

Separate item construction from data loading

The builder asks for a widget at an index in data you already have. Pagination is a separate data-management concern. Keep loading flags, page cursors and failures outside the item builder.

Bound a list inside a column

A vertical list normally wants available height. When placed inside a Column, give it a bounded area using Expanded or a deliberately sized container. Adding shrinkWrap to every list can create unnecessary layout work.

Worked example

This is a complete example. Open it with Run example, then use Run inside DartPad.

main.dart
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  home: Scaffold(
    appBar: AppBar(title: const Text('A scrolling lesson list')),
    body: ListView.builder(itemCount: 100,
      itemBuilder: (context, index) => ListTile(
        leading: Text('${index + 1}'),
        title: Text('Lesson ${index + 1}'),
        subtitle: const Text('A lazily built row'),
      )),
  ),
));

Read the result

The example has one hundred logical items. Flutter constructs row widgets as they become relevant to the viewport. Rows can leave the tree while scrolling; important application data should live in a longer-lived model.

Follow one item through its lifetime

The collection contains data for one hundred items, but the builder creates widget descriptions as the scrollable needs them. As rows leave the useful viewport region, their widget instances can be removed. The underlying application data should not disappear merely because a row is no longer visible.

This distinction matters for editing, selection and expansion. Put persistent item state in a suitable owner keyed by stable item identity, not only in a temporary visible row. Use keys when stateful rows can move.

Lazy widget construction is also different from downloading another data page. The builder operates over data already available. Pagination adds a request model, an in-flight guard and a failure/retry policy. Neither mechanism replaces the other.

Practice and verification

Replace each row with an editable item and scroll it out of view. Decide where editing state should live. Then place a heading above the list in a Column and give the list an Expanded region.

How this topic connects

Understand first

Apply it next

Lesson progressMark complete after checking the example and exercise.

Find your next idea

Search lessons, code examples and projects.

Type a few words to start exploring.