Scrollbar
A scrollbar around a scroll view: shows where the scroll window is now and how much is left, and lets you drag the thumb with the mouse. It scrolls nothing itself — its child is the scroll view (
ListView
,
GridView
,
SingleChildScrollView
,
CustomScrollView
).
Type:
wrapper
SizedBox height:240
Scrollbar
ListView
Text "Row 1"
Text "Row 2"
Text "Row 3"
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
thumbVisibility
|
bool | — |
true
— the thumb is always visible, not only while scrolling. On desktop platforms only over
CustomScrollView
, see Bad practices
|
trackVisibility
|
bool | — |
true
— draw a track under the thumb
|
thickness
|
double | — | Thumb thickness in pixels |
radius
|
double | — | Rounding of the thumb's ends (radius, pixels) |
interactive
|
bool | — | Whether the thumb can be dragged and the track tapped |
scrollbarOrientation
|
string | right |
The edge the bar sits at:
left
,
right
,
top
,
bottom
. An unknown value means
right
|
A parameter that is not set comes from the theme and the platform: on a phone, for example, the thumb appears only while scrolling by default.
The bar is drawn only when the content is longer than the scroll window: if everything fits, there is nothing to scroll, and there is no bar even with
thumbVisibility:true
.
Examples
Thumb always visible
SizedBox height:300
Scrollbar thumbVisibility:true trackVisibility:true thickness:10 radius:5
CustomScrollView
SizedBox height:200
ColoredBox color:#4f46e5
SizedBox height:200
ColoredBox color:#7c3aed
SizedBox height:200
ColoredBox color:#059669
Bar on the left
SizedBox height:240
Scrollbar scrollbarOrientation:"left"
ListView
#padding only left:16
Text "Row 1"
Text "Row 2"
Text "Row 3"
Differences between the app and the site
On the site
Scrollbar
draws
only its child
: it has no element of its own. The bar is shown by the browser itself on the scrolling block, by its own rules and in its own style. So
thumbVisibility
,
trackVisibility
,
thickness
,
radius
,
interactive
and
scrollbarOrientation
are not read on the site.
Bad practices
A permanent thumb over ListView on a computer
// BAD — on macOS and Windows the bar does not find the scroll view: in the editor this is the error
// "The Scrollbar's ScrollController has no ScrollPosition attached", and there is no thumb
SizedBox height:300
Scrollbar thumbVisibility:true
ListView
SizedBox height:200
SizedBox height:200
Scrollbar
finds the scroll view through the primary scroll controller.
CustomScrollView
is always attached to it, while
ListView
,
GridView
and
SingleChildScrollView
are attached only on phones. Without
thumbVisibility
the bar works over any scroll view (scroll events are enough for it); a permanent thumb on a computer works only over
CustomScrollView
.
// GOOD — CustomScrollView: the permanent thumb works on every platform
SizedBox height:300
Scrollbar thumbVisibility:true
CustomScrollView
SizedBox height:200
SizedBox height:200
See also
- ListView , GridView — scroll views the bar is put around
- Slivers and CustomScrollView — the scroll view the permanent thumb works with
- SingleChildScrollView — scrolling a single child