paint method

  1. @override
void paint (Canvas canvas, Rect rect, { double gapStart, double gapExtent: 0.0, double gapPercentage: 0.0, TextDirection textDirection })
override

Draw a rounded rectangle around rect using borderRadius.

The borderSide defines the line's color and weight.

The top side of the rounded rectangle may be interrupted by a single gap if gapExtent is non-null. In that case the gap begins at gapStart - gapPadding (assuming that the textDirection is TextDirection.ltr). The gap's width is (gapPadding + gapExtent + gapPadding) * gapPercentage.

Implementation

@override
void paint(Canvas canvas, Rect rect, {
    double gapStart,
    double gapExtent = 0.0,
    double gapPercentage = 0.0,
    TextDirection textDirection,
}) {
  assert(gapExtent != null);
  assert(gapPercentage >= 0.0 && gapPercentage <= 1.0);
  assert(_cornersAreCircular(borderRadius));

  final Paint paint = borderSide.toPaint();
  final RRect outer = borderRadius.toRRect(rect);
  final RRect center = outer.deflate(borderSide.width / 2.0);
  if (gapStart == null || gapExtent <= 0.0 || gapPercentage == 0.0) {
    canvas.drawRRect(center, paint);
  } else {
    final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
    switch (textDirection) {
      case TextDirection.rtl: {
        final Path path = _gapBorderPath(canvas, center, gapStart + gapPadding - extent, extent);
        canvas.drawPath(path, paint);
        break;
      }
      case TextDirection.ltr: {
        final Path path = _gapBorderPath(canvas, center, gapStart - gapPadding, extent);
        canvas.drawPath(path, paint);
        break;
      }
    }
  }
}