paint method

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

Paints the dividers based on the values passed to it.

Implementation

void paint(PaintingContext context, Offset center, Offset? thumbCenter,
    Offset? startThumbCenter, Offset? endThumbCenter,
    {required RenderBox parentBox,
    required SfSliderThemeData themeData,
    SfRangeValues? currentValues,
    dynamic currentValue,
    required Paint? paint,
    required Animation<double> enableAnimation,
    required TextDirection textDirection}) {
  late bool isActive;
  final bool isVertical = _isVertical(parentBox as RenderBaseSlider);

  if (!isVertical) {
    // Added this condition to check whether consider single thumb or
    // two thumbs for finding active range.
    if (startThumbCenter != null) {
      if (!parentBox.isInversed) {
        isActive = center.dx >= startThumbCenter.dx &&
            center.dx <= endThumbCenter!.dx;
      } else {
        isActive = center.dx >= endThumbCenter!.dx &&
            center.dx <= startThumbCenter.dx;
      }
    } else {
      if (!parentBox.isInversed) {
        isActive = center.dx <= thumbCenter!.dx;
      } else {
        isActive = center.dx >= thumbCenter!.dx;
      }
    }
  } else {
    // Added this condition to check whether consider single thumb or
    // two thumbs for finding active range.
    if (startThumbCenter != null) {
      if (!parentBox.isInversed) {
        isActive = center.dy <= startThumbCenter.dy &&
            center.dy >= endThumbCenter!.dy;
      } else {
        isActive = center.dy >= startThumbCenter.dy &&
            center.dy <= endThumbCenter!.dy;
      }
    } else {
      if (!parentBox.isInversed) {
        isActive = center.dy >= thumbCenter!.dy;
      } else {
        isActive = center.dy <= thumbCenter!.dy;
      }
    }
  }

  if (paint == null) {
    paint = Paint();
    final Color begin = isActive
        ? themeData.disabledActiveDividerColor!
        : themeData.disabledInactiveDividerColor!;
    final Color end = isActive
        ? themeData.activeDividerColor!
        : themeData.inactiveDividerColor!;

    paint.color =
        ColorTween(begin: begin, end: end).evaluate(enableAnimation)!;
  }

  final double dividerRadius =
      getPreferredSize(themeData, isActive: isActive).width / 2;
  context.canvas.drawCircle(center, dividerRadius, paint);

  final double? dividerStrokeWidth = isActive
      ? themeData.activeDividerStrokeWidth
      : themeData.inactiveDividerStrokeWidth;
  final Color? dividerStrokeColor = isActive
      ? themeData.activeDividerStrokeColor
      : themeData.inactiveDividerStrokeColor;

  if (dividerStrokeColor != null &&
      dividerStrokeWidth != null &&
      dividerStrokeWidth > 0) {
    // Drawing divider stroke
    context.canvas.drawCircle(
        center,
        dividerStrokeWidth > dividerRadius
            ? dividerRadius / 2
            : dividerRadius - dividerStrokeWidth / 2,
        paint
          ..color = dividerStrokeColor
          ..style = PaintingStyle.stroke
          ..strokeWidth = dividerStrokeWidth > dividerRadius
              ? dividerRadius
              : dividerStrokeWidth);
  }
}