Contents
Coding With Dhrumil

HomeArticles

SliverAppBar in Flutter: A Practical Example Guide

By Dhrumil PatelPublished 4 min read

A SliverAppBar is the AppBar that lives inside a CustomScrollView, which means it can shrink, stick, or float as the user scrolls. It is the widget behind most of the polished profile and detail screens you see in production Flutter apps.

This guide walks through a complete working example, explains each scroll mode in plain terms, and covers the sizing and performance details that tend to bite developers after the first version ships.

What a SliverAppBar Actually Is

A SliverAppBar is not a drop-in replacement for AppBar. It implements the sliver protocol, so it must be placed inside a CustomScrollView (or NestedScrollView) as a direct child of the slivers list. In return you get a header that participates in the scroll physics of the whole page instead of sitting fixed above it.

The key property is expandedHeight. That is the height of the bar when fully expanded, and the collapsed height is driven by the toolbarHeight plus any bottom widget. Between those two states Flutter interpolates the flexibleSpace, which is where the background image or gradient goes.

The other three properties you will use constantly are pinned, floating, and snap. Pinned keeps a collapsed bar visible at the top. Floating makes the bar reappear as soon as the user scrolls up even slightly. Snap forces the floating bar to finish its appear or disappear animation instead of stopping halfway.

  • expandedHeight: total height when fully open, typically 200–320 logical pixels
  • toolbarHeight: collapsed height, defaults to kToolbarHeight (56)
  • flexibleSpace: background layer, usually FlexibleSpaceBar
  • pinned, floating, snap: control how the bar behaves while scrolling

A Complete Working Example

The example below builds a profile screen with a 260-pixel header image, a title that shrinks into the toolbar, and a pinned bar so the back button never disappears. Wrap the whole page in a Scaffold with a body of CustomScrollView and put the SliverAppBar first in the slivers list.

Inside flexibleSpace use a FlexibleSpaceBar with a background of Image.network wrapped in a DecoratedBox with a subtle dark gradient, so white title text stays readable against bright photos. Set collapseMode to CollapseMode.parallax, which is the default and looks best with images.

Below the bar, add a SliverPadding holding a SliverList.builder. Keeping the list a builder matters: a plain SliverList with a large children array builds every row at once and you lose the laziness that makes slivers worth using in the first place.

  • Scaffold > CustomScrollView > [SliverAppBar, SliverPadding(SliverList.builder)]
  • Use FlexibleSpaceBar(title: Text(...)) for the shrinking title
  • Add a SliverToBoxAdapter if you need a non-list block before the list
  • Avoid fixed-height Containers around slivers; use SliverPadding instead

Pinned, Floating, and Snap Compared

Pinned is the safe default for detail screens: the user always has a visible toolbar and a back button. The trade-off is vertical space — you permanently give up 56 pixels plus the status bar height. For content-heavy reading screens that is usually acceptable.

Floating is better for long lists where users scroll back up frequently, like feeds or search results. The bar returns on any upward scroll and leaves again on downward scroll. Without snap it can sit half-revealed, which looks broken to users, so combine floating with snap: true in almost every case.

Combining pinned and floating gives you a bar that stays visible once it has collapsed but also reappears early on upward scroll. It sounds ideal, but the transition can feel jumpy if the flexibleSpace contains a large image, because the image has to re-expand from a small height.

Sizing, Safe Areas, and the Status Bar

The most common visual bug is text sliding under the status bar. SliverAppBar handles top padding automatically when it is the first sliver, but if you wrap it in a SafeArea you double the inset and get a visible gap. Remove the SafeArea around the bar and let the widget do it.

For expandedHeight, a practical range is 200 to 320 logical pixels on phones. Below roughly 180 the parallax effect is barely visible and the image reads as a thin strip. Above 320 you push the first content row off screen on smaller devices, which hurts perceived load time.

If you add a bottom widget such as a TabBar, remember it increases the collapsed height. A TabBar with 48 pixels of height turns a 56-pixel toolbar into a 104-pixel collapsed bar, which is worth checking on a 640-pixel-tall screen before you commit to the design.

  • Do not wrap SliverAppBar in SafeArea; it already accounts for the status bar
  • Keep expandedHeight between 200 and 320 for phone layouts
  • Add the height of any bottom widget to your collapsed-height calculation
  • Use systemOverlayStyle to keep status bar icons legible over images

Performance and Scroll Edge Effects

Network images inside flexibleSpace are the usual performance trap. A full-resolution photo decoded at 3000 pixels wide but displayed in a 400-pixel-wide bar wastes memory and can stutter during the collapse animation. Use cacheWidth on Image.network, or a package that resizes on decode, to keep the decoded bitmap close to the display size.

If you are rebuilding the bar's title from scroll position with a ScrollController listener, throttle it. Listeners fire on every frame during a fling, and calling setState each time rebuilds the whole sliver subtree. Prefer AnimatedBuilder with a ValueNotifier, or let FlexibleSpaceBar handle the fade for you.

For pages with a tab bar and independently scrolling tabs, NestedScrollView with a SliverAppBar in the headerSliverBuilder is the standard pattern. It is also where state loss becomes a real risk, so read up on handling configuration changes without losing state if your app is Kotlin-first and shares patterns across platforms.

Where Slivers Fit in a Larger App

Once you use one sliver, the rest of the page usually wants to be slivers too. Mixing a CustomScrollView with a nested ListView of unbounded height throws a layout error, and wrapping the list in a SizedBox with a fixed height defeats lazy building. Convert the list to SliverList or SliverGrid and keep the tree flat.

It also helps to know how much widget weight a screen carries before adding a collapsing header. A typical Flutter screen already runs into the low hundreds of widgets, as covered in how many widgets a typical Flutter screen really uses, and a decorative SliverAppBar adds a few dozen more. Measure with the widget inspector before optimising blindly.

56Image only104Image + TabBar56Gradient56Search bar56Large title
Collapsed height by SliverAppBar layout (logical pixels) (px)
Collapsed vs expanded heights for common SliverAppBar layouts
LayoutexpandedHeightCollapsed heightNotes
Image header, no bottom24056Parallax image, pinned recommended
Image header + TabBar280104Adds 48 for the tab bar
Gradient header, no image20056Cheapest to render, no decode cost
Search bar in flexibleSpace18056Keep text field out of the collapsed area
Large title, iOS style9656Small delta, subtle collapse only
Toolbar only (replacement)5656No collapse; behaves like AppBar

Key points

  • SliverAppBar must live inside a CustomScrollView; it is not a drop-in AppBar replacement.
  • Use pinned for detail screens and floating with snap for long feeds.
  • Keep expandedHeight between 200 and 320 and never wrap the bar in SafeArea.
  • Resize network images with cacheWidth to avoid jank during the collapse animation.

Flutter Screen Widget and Cost Estimator

Estimate the number of widgets in a screen and a rough development-hour figure from your component counts. Adjust the fields to see how each UI area affects the total effort.

Calculate

Dhrumil Patel

Editor and Flutter contributor

Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.

Related articles

Cupertino vs Material Widgets: Which Style Fits Your App?

Compares look, platform behavior and maintenance effort of the two Flutter design systems.

Flutter Animation Controllers Explained With Timing Numbers

Walks through duration, curve and reverse settings with concrete millisecond examples.

Handling Configuration Changes in Kotlin Without Losing State

Explains rotation and process death scenarios and which save and restore pattern fits each.