Intermediate
Sliver Widgets and CustomScrollView in Flutter
· 8 min read

What Is a Sliver?
Widgets like ListView, GridView and SingleChildScrollView each manage their own scrollable area. When you want to combine an app bar, a grid view below it, and a plain block of text at the bottom into a SINGLE scroll gesture, these widgets fall short. Slivers exist exactly for this: scrollable pieces that each answer 'how much scroll space do I take up and what's my visible portion', working together under a shared scroll coordinator (the Viewport).

CustomScrollView: A Container for Slivers
CustomScrollView takes a list of slivers and lays them out along a single scroll axis. ListView.builder is actually a CustomScrollView + SliverList under the hood; using CustomScrollView directly lets you freely mix these slivers yourself.
CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 200,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Text('Profil'),
background: Image.network(kapakGorseli, fit: BoxFit.cover),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => ListTile(title: Text('Öğe $index')),
childCount: 20,
),
),
],
)SliverAppBar: pinned, floating, snap
SliverAppBar builds an app bar that expands and collapses as you scroll. Three parameters control its behavior: • pinned: when true, the app bar stays fixed at the top of the screen once collapsed; when false, it disappears entirely. • floating: when true, the app bar reappears as soon as the user starts scrolling up, without waiting for them to scroll all the way to the top. • snap: used together with floating; once the app bar becomes partially visible, it 'snaps' to either fully open or fully closed instead of sitting halfway.
SliverList and SliverGrid
SliverList is the sliver counterpart of ListView.builder; it builds items lazily (only the visible ones) via SliverChildBuilderDelegate. SliverGrid works the same way as the counterpart of GridView.builder, with the column count and aspect ratio set through gridDelegate.
SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
),
delegate: SliverChildBuilderDelegate(
(context, index) => UrunKarti(urunler[index]),
childCount: urunler.length,
),
)Embedding Ordinary Widgets: SliverToBoxAdapter
If you want to add a plain, non-sliver widget (such as a Column or a Card) to your slivers list, wrap it in SliverToBoxAdapter. This makes an ordinary widget behave like a single-item sliver.
CustomScrollView(
slivers: [
const SliverAppBar(pinned: true, title: Text('Mağaza')),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16),
child: Text('Bugünün Fırsatları', style: Theme.of(context).textTheme.titleLarge),
),
),
SliverGrid(/* ... */),
],
)Sticky Headers: SliverPersistentHeader
If you want a category title to stay pinned at the top of the screen while the list beneath it scrolls, use SliverPersistentHeader. In your SliverPersistentHeaderDelegate subclass, you define minExtent, maxExtent and the build method; the shrinkOffset parameter tells you how much the header has collapsed, so you can build an animated transition.
Things to Watch Out For
1. Don't Turn Everything Into a Sliver
If you only have a single list or grid and the app bar doesn't need to interact with scrolling, a plain ListView/GridView is enough, and simpler. Reach for CustomScrollView only when you need to combine more than one scrollable area on a single axis.
2. Expanded/Flexible Don't Work Inside Slivers
Expanded and Flexible only make sense inside a Row/Column/Flex; they can't be the direct child of a sliver. If you want a fixed height, use SliverFillRemaining or a SliverToBoxAdapter + SizedBox combination instead.
Conclusion
Slivers are the building blocks that let Flutter combine complex scroll behaviors under a single Viewport. Build expanding and collapsing headers with SliverAppBar, lazy lists with SliverList/SliverGrid, plain content with SliverToBoxAdapter, and sticky headers with SliverPersistentHeader. Stick with a plain ListView when your needs are simple; reach for CustomScrollView once you need to combine more than one scroll behavior.