Slivers in Flutter - Part (1)
What is Sliver? What is CustomScrollView? An In-depth Explanation of SliverList and SliverAppBar with Example.

Search for a command to run...
What is Sliver? What is CustomScrollView? An In-depth Explanation of SliverList and SliverAppBar with Example.

Thank you Kerkeniπ. Glad you liked it.
Lessons from Code, Content, and Consistency

Reliability basics: Outbox pattern + why it matters

Introducing Kafka/Redpanda + move to event-driven workflow

Connect Orders β Inventory (first working service-to-service flow)

Inventory service + gRPC + proto contracts

Slivers are basically a scrollable area, that can be customized. Slivers help us to make the scrolling fancier instead of a normal boring scroll.Slivers are useful for placing multiple scrollable widgets (ListView, GridView) inside it. It means we can handle nested scroll view. Like below -
ListView, GridView, SingleChildScrollView, etc are implementing slivers under the hood. Slivers, you need a special widget called CustomScrollView. All the slivers are placed inside it.CustomScrollView is the Widget that allows different types of scrollable widgets and lists. And these scrollable lists and widgets are called slivers.slivers available. For example - SliverAppBar, SliverGridList, and SliverList, etc.One thing to note here is CustomScrollView only takes Slivers Widgets as a child. Normal widgets like
Container,ListTile, etc will not work.
Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(/**/),
SliverGridList(/**/),
SliverList(/**/),
//......
]
),
);
CustomScrollView has many properties and one of them is slivers. Which takes list slivers as an input.slivers one by one with an example. And then we can define those slivers inside the CustomScrollView.SliverList is a widget that takes lists of items as child, same as ListView and GridView.ListView and GridView and you want to scroll it together. Like below - 
SliverList, has one parameter called delegate. There are two types of delegate - Scaffold(
body: CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Container(
height: 50,
alignment: Alignment.center,
color: index.isEven ? Colors.grey : Colors.amberAccent,
child: Text('List item : $index'),
);
},
childCount: 12,
),
),
],
));
AppBar widget, the difference is that it works with CutomScrollView. title, actions, leading, flexibleSpace etc.pinned, floating, snap, expandedHeight which customizes the behavior of the AppBar. Let's see how these properties affect the scroll behavior, in the below example.SliverAppBar with title and actionScaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
title: Text('Hello Sliver'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
],
)
],
)
);

SliverAppBar:expandedHeight:AppBar when fully expanded.SliverAppBar(
expandedHeight: 200,
title: Text('Hello Sliver'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

pinnned:true: AppBar will not hide on scrollSliverAppBar(
expandedHeight: 200,
pinned: true,
title: Text('Hello Sliver'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

floating:true, then the AppBar will get visible as soon as the user scrolls towards the AppBar.false then the user has to scroll all the way to the top in order to access AppBarSliverAppBar(
expandedHeight: 200,
floating:true
title: Text('Hello Sliver'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

snap:true, Then the whole AppBar will be visible whenever a user tries to scroll toward the AppBar. floating value must have true in order to run snap.SliverAppBar(
expandedHeight: 200,
floating:true,
snap: true,
title: Text('Hello Sliver'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

snap and floating is, snap shows the AppBar at once, whereas the floating shows AppBar as the user scrolls up.
You can try different combinations of
floating,pinned, andsnapto get various results.
flexibleSpacebackground and various collapseModes to the AppBar.title property also. It is placed at the bottom. When the user scrolls up, it will transform its position with the transition.SliverAppBar(
flexibleSpace: FlexibleSpaceBar(
title: Text("Welcome to Space"),
background: Image.network("url",fit: BoxFit.cover),
),
expandedHeight: 200,
pinned: true,
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

collapseMode property.collapseMode has 3 mode - parallax, pin, noneSliverAppBar(
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
title: Text("Welcome to Space"),
background: Image.network("url",fit: BoxFit.cover),
),
expandedHeight: 200,
pinned: true,
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

stretchfalse.
stretch a value true.SliverAppBar(
stretch: true,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
title: Text("Welcome to Space"),
background: Image.network("url",fit: BoxFit.cover),
),
expandedHeight: 200,
pinned: true,
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

onStretchTrigger function of SliverAppBar.Note: You have to provide
scrollBehaviorto theMaterialAppfor thebouncingscrolling effect.
stretchModesblur, or fade the image on the overflowing scroll instead of zooming, then you can provide different stretchModes inside the FlexibleSpaceBar.SliverAppBar(
stretch: true,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
title: Text("Welcome to Space"),
background: Image.network("url",fit: BoxFit.cover),
stretchModes: [
StretchMode.fadeTitle, // fades out the title
StretchMode.blurBackground, // blur out the background
StretchMode.zoomBackground // zoom the background
],
),
expandedHeight: 200,
pinned: true,
actions: <Widget>[
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {/* ... */},
),
]),

