paint method
- PaintingContext context,
- Offset center, {
- required Animation<
double> activationAnimation, - required Animation<
double> enableAnimation, - required bool isDiscrete,
- required TextPainter labelPainter,
- required RenderBox parentBox,
- required SliderThemeData sliderTheme,
- required TextDirection textDirection,
- required double value,
- required double textScaleFactor,
- required Size sizeWithOverflow,
Paints the shape, taking into account the state passed to it.
The context
argument is the same as the one that includes the Slider's
render box.
The center
argument is the offset for where this shape's center should be
painted. This offset is relative to the origin of the context
canvas.
The activationAnimation
argument is an animation triggered when the user
begins to interact with the slider. It reverses when the user stops interacting
with the slider.
The enableAnimation
argument is an animation triggered when the Slider
is enabled, and it reverses when the slider is disabled. The Slider is
enabled when Slider.onChanged is not null.Use this to paint intermediate
frames for this shape when the slider changes enabled state.
The isDiscrete
argument is true if Slider.divisions is non-null. When
true, the slider will render tick marks on top of the track.
If the labelPainter
argument is non-null, then TextPainter.paint
should be called on the labelPainter
with the location that the label
should appear. If the labelPainter
argument is null, then no label was
supplied to the Slider.
The parentBox
argument is the RenderBox of the Slider. Its attributes,
such as size, can be used to assist in painting this shape.
the sliderTheme
argument is the theme assigned to the Slider that this
shape belongs to.
The textDirection
argument can be used to determine how any extra text
or graphics (besides the text painted by the labelPainter
) should be
positioned. The labelPainter
already has the textDirection
set.
The value
argument is the current parametric value (from 0.0 to 1.0) of
the slider.
The textScaleFactor
argument can be used to determine whether the
component should paint larger or smaller, depending on whether
textScaleFactor
is greater than 1 for larger, and between 0 and 1 for
smaller. It's usually computed from MediaQueryData.textScaler.
The sizeWithOverflow
argument can be used to determine the bounds the
drawing of the components that are outside of the regular slider bounds.
It's the size of the box, whose center is aligned with the slider's
bounds, that the value indicators must be drawn within. Typically, it is
bigger than the slider.
Implementation
@override
void paint(
PaintingContext context,
Offset center, {
required Animation<double> activationAnimation,
required Animation<double> enableAnimation,
required bool isDiscrete,
required TextPainter labelPainter,
required RenderBox parentBox,
required SliderThemeData sliderTheme,
required TextDirection textDirection,
required double value,
required double textScaleFactor,
required Size sizeWithOverflow,
}) {
final Canvas canvas = context.canvas;
final double scale = activationAnimation.value;
_pathPainter.paint(
parentBox: parentBox,
canvas: canvas,
center: center,
scale: scale,
labelPainter: labelPainter,
textScaleFactor: textScaleFactor,
sizeWithOverflow: sizeWithOverflow,
backgroundPaintColor: sliderTheme.valueIndicatorColor!,
strokePaintColor: sliderTheme.valueIndicatorStrokeColor,
);
}