1

I have created a custom paint drawer, which works well, but I liked to create custom brush types like a calligraphy brush, crayon brush, etc...

class DrawingPainter extends CustomPainter {
  DrawingPainter({this.pointsList}) : super();
  List<DrawingPoints> pointsList;
  @override
  void paint(Canvas canvas, Size size) {
    for (int i = 0; i < pointsList.length - 1; i++) {
      if (pointsList[i] != null) {
        canvas.saveLayer(Offset.zero & size, Paint());
        if (shouldDrawLine(i)) {
         canvas.drawLine(pointsList[i].points, pointsList[i + 1].points, pointsList[i].paint);
        } else if (shouldDrawPoint(i)) {
          canvas.drawPoints(dartUI.PointMode.polygon, [pointsList[i].points,pointsList[i].points], pointsList[i].paint);
        }
        canvas.restore();
      }
    }
  }

  bool shouldDrawPoint(int i) =>
      pointsList[i] != null && pointsList.length > i + 1 && pointsList[i + 1] == null;

  bool shouldDrawLine(int i) =>
      pointsList[i] != null && pointsList.length > i + 1 && pointsList[i + 1] != null;

  @override
  bool shouldRepaint(DrawingPainter oldDelegate) => true;
}

this is my code for the drawing. How can I modify the brush drawing pattern like those types of brushes?

0 Answers0