ScrollbarPainter class Null safety

Paints a scrollbar's track and thumb.

The size of the scrollbar along its scroll direction is typically proportional to the percentage of content completely visible on screen, as long as its size isn't less than minLength and it isn't overscrolling.

Unlike CustomPainters that subclasses CustomPainter and only repaint when shouldRepaint returns true (which requires this CustomPainter to be rebuilt), this painter has the added optimization of repainting and not rebuilding when:

  • the scroll position changes; and
  • when the scrollbar fades away.

Calling update with the new ScrollMetrics will repaint the new scrollbar position.

Updating the value on the provided fadeoutOpacityAnimation will repaint with the new opacity.

You must call dispose on this ScrollbarPainter when it's no longer used.

See also:

Inheritance
Implemented types

Constructors

ScrollbarPainter({required Color color, required Animation<double> fadeoutOpacityAnimation, Color trackColor = const Color(0x00000000), Color trackBorderColor = const Color(0x00000000), TextDirection? textDirection, double thickness = _kScrollbarThickness, EdgeInsets padding = EdgeInsets.zero, double mainAxisMargin = 0.0, double crossAxisMargin = 0.0, Radius? radius, OutlinedBorder? shape, double minLength = _kMinThumbExtent, double? minOverscrollLength, ScrollbarOrientation? scrollbarOrientation})
Creates a scrollbar with customizations given by construction arguments.

Properties

color Color
Color of the thumb. Mustn't be null.
read / write
crossAxisMargin double
Distance from the scrollbar thumb to the nearest cross axis edge in logical pixels. [...]
read / write
fadeoutOpacityAnimation Animation<double>
An opacity Animation that dictates the opacity of the thumb. Changes in value of this Listenable will automatically trigger repaints. Mustn't be null.
final
hashCode int
The hash code for this object. [...]
read-only, inherited
hasListeners bool
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
mainAxisMargin double
Distance from the scrollbar's start and end to the edge of the viewport in logical pixels. It affects the amount of available paint area. [...]
read / write
minLength 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. [...]
read / write
minOverscrollLength double
The preferred smallest size the scrollbar thumb can shrink to when viewport is overscrolled. [...]
read / write
padding EdgeInsets
The amount of space by which to inset the scrollbar's start and end, as well as its side to the nearest edge, in logical pixels. [...]
read / write
radius Radius?
Radius of corners if the scrollbar should have rounded corners. [...]
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
scrollbarOrientation ScrollbarOrientation?
Dictates the orientation of the scrollbar. [...]
read / write
semanticsBuilder SemanticsBuilderCallback?
Returns a function that builds semantic information for the picture drawn by this painter. [...]
read-only, override
shape OutlinedBorder?
The OutlinedBorder of the scrollbar's thumb. [...]
read / write
textDirection TextDirection?
TextDirection of the BuildContext which dictates the side of the screen the scrollbar appears in (the trailing side). Must be set prior to calling paint.
read / write
thickness double
Thickness of the scrollbar in its cross-axis in logical pixels. Mustn't be null.
read / write
trackBorderColor Color
Color of the track border. Mustn't be null.
read / write
trackColor Color
Color of the track. Mustn't be null.
read / write

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes. [...]
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed). [...]
override
getTrackToScroll(double thumbOffsetLocal) double
Convert between a thumb track position and the corresponding scroll position. [...]
hitTest(Offset? position) bool?
Called whenever a hit test is being performed on an object that is using this custom paint delegate. [...]
override
hitTestInteractive(Offset position, PointerDeviceKind kind, {bool forHover = false}) bool
Same as hitTest, but includes some padding when the PointerEvent is caused by PointerDeviceKind.touch to make sure that the region isn't too small to be interacted with by the user. [...]
hitTestOnlyThumbInteractive(Offset position, PointerDeviceKind kind) bool
Same as hitTestInteractive, but excludes the track portion of the scrollbar. Used to evaluate interactions with only the scrollbar thumb.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyListeners() → void
Call all the registered listeners. [...]
paint(Canvas canvas, Size size) → void
Called whenever the object needs to paint. The given Canvas has its coordinate space configured such that the origin is at the top left of the box. The area of the box is the size of the size argument. [...]
override
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes. [...]
inherited
shouldRebuildSemantics(covariant CustomPainter oldDelegate) bool
Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former). [...]
override
shouldRepaint(covariant ScrollbarPainter oldDelegate) bool
Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former). [...]
override
toString() String
A string representation of this object. [...]
inherited
update(ScrollMetrics metrics, AxisDirection axisDirection) → void
Update with new ScrollMetrics. If the metrics change, the scrollbar will show and redraw itself based on these new metrics. [...]
updateThickness(double nextThickness, Radius nextRadius) → void
Update and redraw with new scrollbar thickness and radius.

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited