FlutterBasic 2 min read

Flutter scrolling: one viewport and composable slivers

Combine a header and a long list in one CustomScrollView, and avoid accidental unbounded nested scrolling.

On this page

A screen with a header and a long list should usually have a clear owner of vertical scrolling. Nesting a long list inside a SingleChildScrollView often creates constraint problems or forces unnecessary measurement.

Compose one scrollable region

Slivers describe portions of a scrolling viewport. A box widget can enter that system through SliverToBoxAdapter. A sliver list builds repeated content within the same scroll position.

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('One scroll owner')),
    body: CustomScrollView(slivers: [
      const SliverToBoxAdapter(child: Padding(padding: EdgeInsets.all(24),
        child: Text('Course contents', style: TextStyle(fontSize: 28)))),
      SliverList(delegate: SliverChildBuilderDelegate(
        (context, index) => ListTile(title: Text('Topic ${index + 1}')),
        childCount: 60)),
    ]),
  ),
));

Read the result

The heading and rows share a viewport. Use sliver-specific widgets within the slivers list; ordinary children need an adapter. A short form may fit a SingleChildScrollView well, while a long dynamic list benefits from lazy sliver construction.

Think in one scroll position

The heading, list items and footer are parts of one document. CustomScrollView gives that document one viewport and one scroll position. SliverToBoxAdapter translates an ordinary box into that system; SliverList supplies repeated lazily built children.

Adding another vertical scroll view around the same region can create competing gestures and unbounded measurement. Conversely, a short form may legitimately use one SingleChildScrollView because all of its children are a small, known set. Choose from the amount and behavior of content.

When a layout fails, write down which widget owns height and which owns scrolling. The ListView guide explains item construction; the constraints lesson explains why a scrolling region cannot promise a finite height to every flex child.

Practice and verification

Add a footer through SliverToBoxAdapter. Confirm it appears after the final item and uses the same scroll position. Explain why wrapping the entire example in another vertical scroll view would be redundant.

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.