paint method
void
paint(
- PaintingContext context,
- Offset center, {
- required RenderBox parentBox,
- required SliderThemeData sliderTheme,
- required Animation<
double> enableAnimation, - required TextDirection textDirection,
- required Offset thumbCenter,
- required bool isEnabled,
override
Paint method
Implementation
@override
void paint(
PaintingContext context,
Offset center, {
required RenderBox parentBox,
required SliderThemeData sliderTheme,
required Animation<double> enableAnimation,
required TextDirection textDirection,
required Offset thumbCenter,
required bool isEnabled,
}) {
Color? begin;
Color? end;
switch (textDirection) {
case TextDirection.ltr:
final bool isTickMarkRightOfThumb = center.dx > thumbCenter.dx;
begin = isTickMarkRightOfThumb
? sliderTheme.disabledInactiveTickMarkColor
: sliderTheme.disabledActiveTickMarkColor;
end = isTickMarkRightOfThumb ? sliderTheme.inactiveTickMarkColor : sliderTheme.activeTickMarkColor;
break;
case TextDirection.rtl:
final bool isTickMarkLeftOfThumb = center.dx < thumbCenter.dx;
begin =
isTickMarkLeftOfThumb ? sliderTheme.disabledInactiveTickMarkColor : sliderTheme.disabledActiveTickMarkColor;
end = isTickMarkLeftOfThumb ? sliderTheme.inactiveTickMarkColor : sliderTheme.activeTickMarkColor;
break;
}
/// Array to store index
if (canvasXIndex.length != inputValues!.length) {
canvasXIndex.add(center.dx);
}
/// Tick mark paint
final Paint tickMarkPaint = Paint()..color = ColorTween(begin: begin, end: end).evaluate(enableAnimation)!;
/// Marker paint
final Paint markerPaint = Paint()
..strokeWidth = 1
..strokeCap = StrokeCap.round
..color = ColorTween(begin: begin, end: end).evaluate(enableAnimation)!;
if (tickMarkRadius! > 0) {
context.canvas.drawCircle(Offset(center.dx, center.dy), tickMarkRadius!, tickMarkPaint);
int index = 0;
for (var element in canvasXIndex) {
if (element == center.dx) {
break;
}
index++;
}
context.canvas.drawLine(
Offset(center.dx, center.dy),
Offset(center.dx, labelDirection == NumericLabelDirection.below ? (center.dy + 15) : (center.dy - 15)),
markerPaint);
TextSpan span = TextSpan(style: numericLabelTextStyle, text: currencyPrefix! + inputValues![index].toString());
TextPainter tp = TextPainter(text: span, textAlign: TextAlign.left, textDirection: TextDirection.ltr);
tp.layout();
tp.paint(
context.canvas,
Offset(labelDirection == NumericLabelDirection.below ? (center.dx - 12) : (center.dx - 10),
labelDirection == NumericLabelDirection.below ? (center.dy + 20) : (center.dy - 35)));
}
}