Back to results for “Responsive UI”
Flutter › Flutter Slivers & Custom Scroll Effects

What is SliverAppBar, and how does its expandedHeight property together with FlexibleSpaceBar let you create the popular collapsing header effect commonly seen in many modern apps?

Beginner

Answer

SliverAppBar is a genuinely specialized sliver specifically designed to work properly within a CustomScrollView, and setting its expandedHeight property to a value considerably larger than its normal standard app bar height, combined with using a FlexibleSpaceBar as its flexibleSpace, creates the now genuinely popular collapsing header effect where a large header image or title smoothly and gradually shrinks down as a user actively scrolls, eventually settling and properly collapsing into a genuinely much more compact, standard sized app bar once the user has scrolled sufficiently far down the overall page.
SliverAppBar(
  expandedHeight: 250,
  pinned: true,
  flexibleSpace: FlexibleSpaceBar(
    background: Image.network(coverImageUrl, fit: BoxFit.cover),
    title: Text('Product Name'),
  ),
)
Real-world example A product detail screen uses SliverAppBar to properly display a genuinely large, prominent product photo that smoothly and gradually shrinks and collapses into a compact standard app bar as the user actively scrolls further down to read the remaining detailed product description.

Common follow-ups: What does the pinned property specifically do on SliverAppBar?;What is the difference between the pinned, floating, and snap properties on SliverAppBar?