Module 6
Topic 4

Slivers

Building fancy scrolling effects — from collapsing headers to elastic scrolling — using Flutter's sliver system.

Flutter Slivers Docs Slivers Guide
What Are Slivers?

A sliver is a portion of a scrollable area that you can define to behave in a special way. Slivers are the building blocks of custom scrolling in Flutter — they give you fine-grained control over how your scrollable content behaves.

💡 Key Concept

Think of slivers as "scrollable pieces" that can be combined to create complex scrolling effects. Unlike ListView or GridView which are self-contained, slivers are components that can be arranged in a CustomScrollView to create custom scroll experiences.

📱
SliverAppBar
Collapsible app bar that expands/contracts
Medium-style profile headers
📋
SliverList
Scrollable list of items
Standard list with custom headers
📊
SliverGrid
Scrollable grid of items
Pinterest-style layout
📌
SliverPersistentHeader
Header that stays visible while scrolling
Sticky section headers
🔄
SliverToBoxAdapter
Wrap a regular widget as a sliver
Mix static content with scrollable content
📐
SliverPadding
Add padding around slivers
Add spacing between slivers
CustomScrollView

CustomScrollView is the container that holds your slivers. It's the root of any sliver-based scrolling implementation.

CustomScrollView slivers: [
SliverAppBar SliverList SliverGrid SliverPersistentHeader
]
SliverAppBar

SliverAppBar is one of the most commonly used slivers. It creates a collapsible app bar that can expand and contract as the user scrolls.

💡 SliverAppBar Properties

  • floating – App bar reappears when scrolling up
  • pinned – App bar stays at the top when collapsed
  • snap – App bar snaps open when partially scrolled
  • expandedHeight – Height when fully expanded
  • collapsedHeight – Height when fully collapsed
  • flexibleSpace – Content that scales with the app bar
SliverList and SliverGrid

SliverList and SliverGrid are the scrollable content slivers that display collections of items.

💡 Delegate Options

  • SliverChildBuilderDelegate – Build items lazily (recommended)
  • SliverChildListDelegate – Provide a pre-built list of children
  • SliverChildBuilderDelegate – Better for large lists (lazy loading)
SliverPersistentHeader

SliverPersistentHeader creates a header that sticks to the top of the scroll view as you scroll past it. This is perfect for section headers, sticky tabs, or any content that should remain visible.

✅ When to Use SliverPersistentHeader

  • Sticky section headers – Like a contacts list (A, B, C...)
  • Sticky tabs – Tab bar that stays at the top
  • Sticky search bars – Search field that scrolls with content
  • Sticky filters – Filter options that remain accessible
Mixing Slivers

The real power of slivers comes from combining different types to create complex, polished scrolling experiences.

Step-by-Step Implementation

Follow these steps to implement slivers in your Flutter app:

1.
Start with CustomScrollView – Replace ListView with CustomScrollView
2.
Add SliverAppBar – Create a collapsible app bar at the top
3.
Add static content – Use SliverToBoxAdapter for non-scrollable widgets
4.
Add scrollable content – Use SliverList or SliverGrid
5.
Add sticky headers – Use SliverPersistentHeader for section headers
6.
Add spacing – Use SliverPadding to add space between slivers
7.
Test and refine – Adjust heights, behaviors, and animations
Common Mistakes
❌ Mistake 1: Not using SliverToBoxAdapter for regular widgets

You can't put regular widgets directly in CustomScrollView.slivers .

✅ Correct: Wrap with SliverToBoxAdapter

Use SliverToBoxAdapter(child: YourWidget()) to add regular widgets to a sliver list.

❌ Mistake 2: Forgetting to implement shouldRebuild

Not implementing shouldRebuild in custom delegates can cause unnecessary rebuilds.

✅ Correct: Implement shouldRebuild

Always implement shouldRebuild in your custom delegates to control when they rebuild.

❌ Mistake 3: Using SliverChildListDelegate for large lists

SliverChildListDelegate builds all children at once, which is inefficient for large lists.

✅ Correct: Use SliverChildBuilderDelegate

Use SliverChildBuilderDelegate for lazy loading of large lists.

❌ Mistake 4: Hardcoding heights

Hardcoding heights in slivers can cause layout issues on different screen sizes.

✅ Correct: Use responsive heights

Use MediaQuery , LayoutBuilder , or dynamic calculations for sliver heights.

Resources

📚 Learning Resources

🔗 Related Lessons

🎯 Key Takeaway

Slivers are the building blocks of custom scrolling in Flutter. Using CustomScrollView with different sliver types — SliverAppBar , SliverList , SliverGrid , and SliverPersistentHeader — you can create fancy scrolling effects like collapsing headers, sticky sections, and elastic scrolling. Always use SliverChildBuilderDelegate for large lists and implement shouldRebuild in custom delegates for performance.