Answer
Overview
Slivers are special scrollable components in Flutter that can be combined inside a
text
CustomScrollViewThe word "sliver" literally means "a thin piece" — each sliver is a piece of the scrollable area.
Why Slivers?
Normal scrolling with
text
ListView- Combine multiple scrollable sections
- Create collapsible app bars
- Create sticky headers
- Mix grids and lists in one scroll view
CustomScrollView + Slivers
dartCustomScrollView( slivers: [ // Collapsing app bar SliverAppBar( title: Text('My App'), expandedHeight: 200, pinned: true, flexibleSpace: FlexibleSpaceBar( background: Image.network(url, fit: BoxFit.cover), ), ), // Grid section SliverGrid( delegate: SliverChildBuilderDelegate( (context, index) => Card(child: Center(child: Text('Grid $index'))), childCount: 6, ), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2), ), // List section SliverList( delegate: SliverChildBuilderDelegate( (context, index) => ListTile(title: Text('List Item $index')), childCount: 20, ), ), ], )
Common Sliver Widgets
| Widget | Description |
|---|---|
text | Collapsible/floating app bar |
text | Lazy list (replaces ListView) |
text | Lazy grid (replaces GridView) |
text | Custom sticky header |
text | Wrap any normal widget in a sliver |
text | Fill remaining scroll area |
text | Add padding around a sliver |
text | Performance list with fixed item height |
text | Animated sliver list |
SliverToBoxAdapter (Wrap Any Widget)
dartCustomScrollView( slivers: [ SliverAppBar(title: Text('App')), SliverToBoxAdapter( child: Padding( padding: EdgeInsets.all(16), child: Text('Featured Section', style: TextStyle(fontSize: 20)), ), ), SliverList( delegate: SliverChildBuilderDelegate( (context, index) => ListTile(title: Text('Item $index')), childCount: 10, ), ), SliverFillRemaining( child: Center(child: Text('End of list')), ), ], )
Normal Widgets vs Sliver Equivalents
| Normal Widget | Sliver Equivalent |
|---|---|
text | text |
text | text |
text | text |
| Any widget | text |
Key Rule: Slivers only work inside
. Outside of it, use normal widgets. Slivers are powerful but have more complexity — use them only when you need coordinated scrolling effects.textCustomScrollView