ScrollbarPainter class

A CustomPainter for painting scrollbars.

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
Implements

Constructors

ScrollbarPainter({@required Color color, @required TextDirection textDirection, @required double thickness, @required Animation<double> fadeoutOpacityAnimation, double mainAxisMargin: 0.0, double crossAxisMargin: 0.0, Radius radius, double minLength: _kMinThumbExtent })
Creates a scrollbar with customizations given by construction arguments.

Properties

color Color
Color of the thumb. Mustn't be null.
final
crossAxisMargin double
Distance from the scrollbar's side to the nearest edge in pixels. Musn't be null.
final
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
mainAxisMargin double
Distance from the scrollbar's start and end to the edge of the viewport in pixels. Mustn't be null.
final
minLength double
The smallest size the scrollbar can shrink to when the total scrollable extent is large and the current visible viewport is small. Mustn't be null.
final
radius Radius
Radius of corners if the scrollbar should have rounded corners. [...]
final
semanticsBuilder SemanticsBuilderCallback
Returns a function that builds semantic information for the picture drawn by this painter. [...]
read-only
textDirection TextDirection
TextDirection of the BuildContext which dictates the side of the screen the scrollbar appears in (the trailing side). Mustn't be null.
final
thickness double
Thickness of the scrollbar in its cross-axis in pixels. Mustn't be null.
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

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). [...]
hitTest(Offset position) bool
Called whenever a hit test is being performed on an object that is using this custom paint delegate. [...]
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. [...]
shouldRebuildSemantics(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). [...]
shouldRepaint(ScrollbarPainter old) 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). [...]
update(ScrollMetrics metrics, AxisDirection axisDirection) → void
Update with new ScrollMetrics. The scrollbar will show and redraw itself based on these new metrics. [...]
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyListeners() → void
Call all the registered listeners. [...]
@protected, inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

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