ScrollbarPainter class
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:
- Scrollbar for a widget showing a scrollbar around a Scrollable in the Material Design style.
- CupertinoScrollbar for a widget showing a scrollbar around a Scrollable in the iOS style.
- Inheritance
-
- Object
- ChangeNotifier
- ScrollbarPainter
- 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, Radius? trackRadius, OutlinedBorder? shape, double minLength = _kMinThumbExtent, double? minOverscrollLength, ScrollbarOrientation? scrollbarOrientation, bool ignorePointer = false}) - Creates a scrollbar with customizations given by construction arguments.
Properties
- color ↔ Color
-
Color of the thumb. Mustn't be null.
getter/setter pair
- crossAxisMargin ↔ double
-
Distance from the scrollbar thumb to the nearest cross axis edge
in logical pixels.
getter/setter pair
-
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.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- ignorePointer ↔ bool
-
Whether the painter will be ignored during hit testing.
getter/setter pair
- mainAxisMargin ↔ double
-
Distance from the scrollbar thumb's start and end to the edge of the
viewport in logical pixels. It affects the amount of available paint area.
getter/setter pair
- 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.
getter/setter pair
- minOverscrollLength ↔ double
-
The preferred smallest size the scrollbar thumb can shrink to when viewport is
overscrolled.
getter/setter pair
- 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.
getter/setter pair
- radius ↔ Radius?
-
Radius of corners if the scrollbar should have rounded corners.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollbarOrientation ↔ ScrollbarOrientation?
-
Dictates the orientation of the scrollbar.
getter/setter pair
- semanticsBuilder → SemanticsBuilderCallback?
-
Returns a function that builds semantic information for the picture drawn
by this painter.
no setteroverride
- shape ↔ OutlinedBorder?
-
The OutlinedBorder of the scrollbar's thumb.
getter/setter pair
- 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.
getter/setter pair
- thickness ↔ double
-
Thickness of the scrollbar in its cross-axis in logical pixels. Mustn't be null.
getter/setter pair
- trackBorderColor ↔ Color
-
Color of the track border. Mustn't be null.
getter/setter pair
- trackColor ↔ Color
-
Color of the track. Mustn't be null.
getter/setter pair
- trackRadius ↔ Radius?
-
Radius of corners of the Scrollbar's track.
getter/setter pair
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 will throw after the object is disposed).
override
-
getThumbScrollOffset(
) → double - The thumb's corresponding scroll offset in the track.
-
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 nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
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.
override
-
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