paint method

void paint(
  1. PaintingContext context,
  2. Offset center, {
  3. required RenderBox parentBox,
  4. required RenderBox? child,
  5. required SfSliderThemeData themeData,
  6. SfRangeValues? currentValues,
  7. dynamic currentValue,
  8. required Paint? paint,
  9. required Animation<double> enableAnimation,
  10. required TextDirection textDirection,
  11. required SfThumb? thumb,
})

Paints the thumb based on the values passed to it.

Implementation

void paint(PaintingContext context, Offset center,
    {required RenderBox parentBox,
    required RenderBox? child,
    required SfSliderThemeData themeData,
    SfRangeValues? currentValues,
    dynamic currentValue,
    required Paint? paint,
    required Animation<double> enableAnimation,
    required TextDirection textDirection,
    required SfThumb? thumb}) {
  final double radius = getPreferredSize(themeData).width / 2;
  final bool hasThumbStroke = themeData.thumbStrokeColor != null &&
      themeData.thumbStrokeColor != Colors.transparent &&
      themeData.thumbStrokeWidth != null &&
      themeData.thumbStrokeWidth! > 0;

  final bool showThumbShadow = themeData.thumbColor != Colors.transparent;
  // ignore: avoid_as
  final RenderBaseSlider parentRenderBox = parentBox as RenderBaseSlider;
  if (showThumbShadow) {
    final Path path = Path();
    final bool isThumbActive =
        (parentRenderBox.activeThumb == thumb || thumb == null) &&
            parentRenderBox.currentPointerType != null &&
            parentRenderBox.currentPointerType != PointerType.up;
    path.addOval(Rect.fromCircle(center: center, radius: radius));
    final double thumbElevation = isThumbActive
        ? parentRenderBox.thumbElevationTween.evaluate(enableAnimation)
        : defaultElevation;

    context.canvas.drawShadow(path, shadowColor, thumbElevation, true);
  }

  if (themeData is SfRangeSliderThemeData &&
      !hasThumbStroke &&
      _isThumbOverlapping(parentBox) &&
      themeData.thumbColor != Colors.transparent &&
      themeData.overlappingThumbStrokeColor != null) {
    context.canvas.drawCircle(
        center,
        radius,
        Paint()
          ..color = themeData.overlappingThumbStrokeColor!
          ..style = PaintingStyle.stroke
          ..isAntiAlias = true
          ..strokeWidth = 1.0);
  }

  if (paint == null) {
    paint = Paint();
    paint.isAntiAlias = true;
    paint.color = ColorTween(
            begin: themeData.disabledThumbColor, end: themeData.thumbColor)
        .evaluate(enableAnimation)!;
  }

  context.canvas.drawCircle(center, radius, paint);
  if (child != null) {
    context.paintChild(
        child,
        Offset(center.dx - (child.size.width) / 2,
            center.dy - (child.size.height) / 2));
  }

  if (themeData.thumbStrokeColor != null &&
      themeData.thumbStrokeWidth != null &&
      themeData.thumbStrokeWidth! > 0) {
    final Paint strokePaint = Paint()
      ..color = themeData.thumbStrokeColor!
      ..style = PaintingStyle.stroke
      ..strokeWidth = themeData.thumbStrokeWidth! > radius
          ? radius
          : themeData.thumbStrokeWidth!;
    context.canvas.drawCircle(
        center,
        themeData.thumbStrokeWidth! > radius
            ? radius / 2
            : radius - themeData.thumbStrokeWidth! / 2,
        strokePaint);
  }
}