2

I am trying to create a more complex customPaint and want to add a border to it. From the picture you can see the shape (In blue) and the partial border (in white)

The way I am creating the white border is with a secondary customPaint right now. My question is, is there an easier way of adding a border to the existing customPaint, as doing the corners of the rectangle can be annoying by itself and doesn't seem like an elegant way of doing it.

enter image description here

My code right now, without the border

      Path.combine(
        PathOperation.intersect,
        Path()
          ..addRRect(RRect.fromLTRBR(
              xCanvasLeft,
              xCanvasTop,
              xCanvasRight,
              xCanvasBot,
              const Radius.circular(canvasRadius))),
        Path()
          ..addOval(Rect.fromCircle(
              center: Offset(xHole, yHoleTop),
              radius: holeRadius))
          ..addOval(Rect.fromCircle(
              center: Offset(xHole,
                  yHoleBot),
              radius: holeRadius))
          ..close(),
      ),
      paint,
    );

EDIT: I am also wondering how resource heavy custom paint is?

0

1 Answer 1

0

I simply use the same painter for adding the border with the stroke width property.

Paint paintBorder = Paint()
  ..style = PaintingStyle.stroke
  ..strokeWidth = 6.0
  ..color = Colors.blue;
Paint paintFill = Paint();

Then while drawing the path just draw the fill before the border like this

canvas.drawPath(path, paintFill);
canvas.drawPath(path, paintBorder);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.