text
stringlengths
1
474
scroll and also offers a variety of widgets
that you can customize to create specific scrolling
behavior.<topic_end>
<topic_start>
Basic scrolling
Many Flutter widgets support scrolling out of the box
and do most of the work for you. For example,
SingleChildScrollView automatically scrolls its
child when necessary. Other useful widgets include
ListView and GridView.
You can check out more of these widgets on the
scrolling page of the Widget catalog.<topic_end>
<topic_start>
Infinite scrolling
When you have a long list of items
in your ListView or GridView (including an infinite list),
you can build the items on demand
as they scroll into view. This provides a much
more performant scrolling experience.
For more information, check out
ListView.builder or GridView.builder.<topic_end>
<topic_start>
Specialized scrollable widgets
The following widgets provide more specific scrolling
behavior.A video on using DraggableScrollableSheetTurn the scrollable area into a wheel! ListWheelScrollView<topic_end>
<topic_start>
Fancy scrolling
Perhaps you want to implement elastic scrolling,
also called scroll bouncing. Or maybe you want to
implement other dynamic scrolling effects, like parallax scrolling.
Or perhaps you want a scrolling header with very specific behavior,
such as shrinking or disappearing.You can achieve all this and more using the
Flutter Sliver* classes.
A sliver refers to a piece of the scrollable area.
You can define and insert a sliver into a CustomScrollView
to have finer-grained control over that area.For more information, check out
Using slivers to achieve fancy scrolling
and the Sliver classes.<topic_end>
<topic_start>
Nested scrolling widgets
How do you nest a scrolling widget
inside another scrolling widget
without hurting scrolling performance?
Do you set the ShrinkWrap property to true,
or do you use a sliver?Check out the “ShrinkWrap vs Slivers” video:
<topic_end>
<topic_start>Using slivers to achieve fancy scrolling
A sliver is a portion of a scrollable area that you
can define to behave in a special way.
You can use slivers to achieve custom scrolling effects,
such as elastic scrolling.For a free, instructor-led video workshop that uses DartPad,
check out the following video about using slivers.<topic_end>
<topic_start>Resources
For more information on implementing fancy scrolling effects
in Flutter, see the following resources:<topic_end>
<topic_start>API docs
To learn more about the available sliver APIs,
check out these related API docs:
<topic_end>
<topic_start>Place a floating app bar above a list
To make it easier for users to view a list of items,
you might want to hide the app bar as the user scrolls down the list.
This is especially true if your app displays a “tall”
app bar that occupies a lot of vertical space.Typically, you create an app bar by providing an appBar property to the
Scaffold widget. This creates a fixed app bar that always remains above
the body of the Scaffold.Moving the app bar from a Scaffold widget into a
CustomScrollView allows you to create an app bar
that scrolls offscreen as you scroll through a
list of items contained inside the CustomScrollView.This recipe demonstrates how to use a CustomScrollView to display a list of
items with an app bar on top that scrolls offscreen as the user scrolls
down the list using the following steps:<topic_end>
<topic_start>
1. Create a CustomScrollView
To create a floating app bar, place the app bar inside a
CustomScrollView that also contains the list of items.
This synchronizes the scroll position of the app bar and the list of items.
You might think of the CustomScrollView widget as a ListView
that allows you to mix and match different types of scrollable lists
and widgets together.The scrollable lists and widgets provided to the
CustomScrollView are known as slivers. There are several types
of slivers, such as SliverList, SliverGrid, and SliverAppBar.
In fact, the ListView and GridView widgets use the SliverList and
SliverGrid widgets to implement scrolling.For this example, create a CustomScrollView that contains a
SliverAppBar and a SliverList. In addition, remove any app bars
that you provide to the Scaffold widget.
<code_start>Scaffold(
// No appBar property provided, only the body.
body: CustomScrollView(
// Add the app bar and list of items as slivers in the next steps.
slivers: <Widget>[]),
);<code_end>
<topic_end>
<topic_start>
2. Use SliverAppBar to add a floating app bar
Next, add an app bar to the CustomScrollView.
Flutter provides the SliverAppBar widget which,
much like the normal AppBar widget,
uses the SliverAppBar to display a title,
tabs, images and more.However, the SliverAppBar also gives you the ability to create a “floating”
app bar that scrolls offscreen as the user scrolls down the list.