CupertinoScrollbar class

An iOS style scrollbar.

To add a scrollbar to a ScrollView, wrap the scroll view widget in a CupertinoScrollbar widget.

Learn more about CupertinoScrollbar on the Flutter YouTube channel.

For more information, see RawScrollbar.

When dragging a CupertinoScrollbar thumb, the thickness and radius will animate from thickness and radius to thicknessWhileDragging and radiusWhileDragging, respectively.

This sample shows a CupertinoScrollbar that fades in and out of view as scrolling occurs. The scrollbar will fade into view as the user scrolls, and fade out when scrolling stops. The thickness of the scrollbar will animate from 6 pixels to the thicknessWhileDragging of 10 when it is dragged by the user. The radius of the scrollbar thumb corners will animate from 34 to the radiusWhileDragging of 0 when the scrollbar is being dragged by the user.

To see it in action, copy and run this code snippet on DartPad.

import 'package:cupertino_ui/cupertino_ui.dart';

/// Flutter code sample for [CupertinoScrollbar].

void main() => runApp(const ScrollbarApp());

class ScrollbarApp extends StatelessWidget {
  const ScrollbarApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      theme: CupertinoThemeData(brightness: .light),
      home: ScrollbarExample(),
    );
  }
}

class ScrollbarExample extends StatelessWidget {
  const ScrollbarExample({super.key});

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: Text('CupertinoScrollbar Sample'),
      ),
      child: CupertinoScrollbar(
        thickness: 6.0,
        thicknessWhileDragging: 10.0,
        radius: const .circular(34.0),
        radiusWhileDragging: Radius.zero,
        child: ListView.builder(
          itemCount: 120,
          itemBuilder: (BuildContext context, int index) {
            return Center(
              child: Padding(
                padding: const .all(8.0),
                child: Text('Item $index'),
              ),
            );
          },
        ),
      ),
    );
  }
}

When thumbVisibility is true, the scrollbar thumb will remain visible without the fade animation. This requires that a ScrollController is provided to controller, or that the PrimaryScrollController is available.

To see it in action, copy and run this code snippet on DartPad.

import 'package:cupertino_ui/cupertino_ui.dart';

/// Flutter code sample for [CupertinoScrollbar].

void main() => runApp(const ScrollbarApp());

class ScrollbarApp extends StatelessWidget {
  const ScrollbarApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      theme: CupertinoThemeData(brightness: .light),
      home: ScrollbarExample(),
    );
  }
}

class ScrollbarExample extends StatefulWidget {
  const ScrollbarExample({super.key});

  @override
  State<ScrollbarExample> createState() => _ScrollbarExampleState();
}

class _ScrollbarExampleState extends State<ScrollbarExample> {
  final ScrollController _controllerOne = ScrollController();

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: Text('CupertinoScrollbar Sample'),
      ),
      child: CupertinoScrollbar(
        thickness: 6.0,
        thicknessWhileDragging: 10.0,
        radius: const .circular(34.0),
        radiusWhileDragging: Radius.zero,
        controller: _controllerOne,
        thumbVisibility: true,
        child: ListView.builder(
          controller: _controllerOne,
          itemCount: 120,
          itemBuilder: (BuildContext context, int index) {
            return Center(
              child: Padding(
                padding: const .all(8.0),
                child: Text('Item $index'),
              ),
            );
          },
        ),
      ),
    );
  }
}

See also:

  • ListView, which displays a linear, scrollable list of children.
  • GridView, which displays a 2 dimensional, scrollable array of children.
  • Scrollbar, a Material Design scrollbar.
  • RawScrollbar, a basic scrollbar that fades in and out, extended by this class to add more animations and behaviors.
Inheritance

Constructors

CupertinoScrollbar({Key? key, required Widget child, ScrollController? controller, bool? thumbVisibility, double thickness = defaultThickness, double thicknessWhileDragging = defaultThicknessWhileDragging, Radius radius = defaultRadius, Radius radiusWhileDragging = defaultRadiusWhileDragging, ScrollNotificationPredicate? notificationPredicate, ScrollbarOrientation? scrollbarOrientation, double mainAxisMargin = _kScrollbarMainAxisMargin})
Creates an iOS style scrollbar that wraps the given child.
const

Properties

child → Widget
The widget below this widget in the tree.
finalinherited
controller → ScrollController?
The ScrollController used to implement Scrollbar dragging.
finalinherited
crossAxisMargin → double
Distance from the scrollbar thumb's side to the nearest cross axis edge in logical pixels.
finalinherited
fadeDuration → Duration
The Duration of the fade animation.
finalinherited
hashCode → int
The hash code for this object.
no setterinherited
interactive → bool?
Whether the Scrollbar should be interactive and respond to dragging on the thumb, or tapping in the track area.
finalinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
mainAxisMargin → double
Distance from the scrollbar thumb's start or end to the nearest edge of the viewport in logical pixels. It affects the amount of available paint area.
finalinherited
minOverscrollLength → double?
The preferred smallest size the scrollbar thumb can shrink to when viewport is overscrolled.
finalinherited
minThumbLength → double
The preferred smallest size the scrollbar thumb can shrink to when the total scrollable extent is large, the current visible viewport is small, and the viewport is not overscrolled.
finalinherited
notificationPredicate → ScrollNotificationPredicate
A check that specifies whether a ScrollNotification should be handled by this widget.
finalinherited
padding → EdgeInsetsGeometry?
The insets by which the scrollbar thumb and track should be padded.
finalinherited
pressDuration → Duration
The Duration of time that a LongPress will trigger the drag gesture of the scrollbar thumb.
finalinherited
radius → Radius?
The Radius of the scrollbar thumb's rounded rectangle corners.
finalinherited
radiusWhileDragging → Radius
The radius of the scrollbar edges when the scrollbar is being dragged by the user.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scrollbarOrientation → ScrollbarOrientation?
Dictates the orientation of the scrollbar.
finalinherited
shape → OutlinedBorder?
The OutlinedBorder of the scrollbar's thumb.
finalinherited
thickness → double?
The thickness of the scrollbar in the cross axis of the scrollable.
finalinherited
thicknessWhileDragging → double
The thickness of the scrollbar when it's being dragged by the user.
final
thumbColor → Color?
The color of the scrollbar thumb.
finalinherited
thumbVisibility → bool?
Indicates that the scrollbar thumb should be visible, even when a scroll is not underway.
finalinherited
timeToFade → Duration
The Duration of time until the fade animation begins.
finalinherited
trackBorderColor → Color?
The color of the scrollbar track's border.
finalinherited
trackColor → Color?
The color of the scrollbar track.
finalinherited
trackRadius → Radius?
The Radius of the scrollbar track's rounded rectangle corners.
finalinherited
trackVisibility → bool?
Indicates that the scrollbar track should be visible.
finalinherited

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → RawScrollbarState<CupertinoScrollbar>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultRadius → const Radius
Default value for radius if it's not specified in CupertinoScrollbar.
defaultRadiusWhileDragging → const Radius
Default value for radiusWhileDragging if it's not specified in CupertinoScrollbar.
defaultThickness → const double
Default value for thickness if it's not specified in CupertinoScrollbar.
defaultThicknessWhileDragging → const double
Default value for thicknessWhileDragging if it's not specified in CupertinoScrollbar.