skip to content

Nested Scrolling

A scroll view inside a Column or inside another scroll view needs a bounded extent, so developers reach for shrinkWrap or NestedScrollView. Interviewers probe why shrinkWrap defeats lazy building.

part ofFlutteroverview, primer and where to startread it →
on this pageshow

explore

questions

5

A Flutter page nests shrinkWrap ListViews with NeverScrollableScrollPhysics inside a SingleChildScrollView and janks with 2,000 rows; why, and how do you fix it?

level: seniorimportance: must knowfreq 55%

basics

~20 s

Inside a SingleChildScrollView a shrinkWrap list gets unbounded height, so its viewport treats every row as visible and builds and lays out all 2,000. NeverScrollableScrollPhysics only passes drags to the outer view. Fix it with one scroll view: a CustomScrollView of sliver lists.

open as a page

In Flutter, what problem does NestedScrollView solve, and why does it need SliverOverlapAbsorber and SliverOverlapInjector?

level: middleimportance: should knowfreq 45%

basics

~20 s

NestedScrollView links an outer scroll view holding a collapsing header to inner scroll views, typically lists inside a TabBarView, so they scroll as one. The absorber records the pinned header's overlap and the injector pads each inner list so its first rows are not hidden.

open as a page

In Flutter, how does a PageView with a PageController work, and what do viewportFraction, onPageChanged and keepPage change?

level: middleimportance: should knowfreq 45%

basics

~20 s

PageView is a scroll view that snaps to whole pages; a PageController, a ScrollController subclass, drives it with jumpToPage, animateToPage and nextPage. viewportFraction sets each page's share of the viewport, onPageChanged fires when the centred page changes, and keepPage restores the page.

open as a page

In Flutter, what is PrimaryScrollController, and why does tapping the iOS status bar scroll some lists to the top but not others?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

PrimaryScrollController is an inherited ScrollController each route provides. Vertical scroll views on Android, iOS and Fuchsia that get no controller of their own attach to it, and Scaffold scrolls it to top on an iOS status-bar tap. A list with its own controller is skipped.

open as a page