paint method

  1. @override
void paint(
  1. Canvas canvas,
  2. Size size,
  3. WorldToScreen worldToScreen,
  4. ScreenToWorld screenToWorld,
  5. double scale,
)
override

Called by the canvas to paint this item onto the screen.

The canvas and size are provided by the Flutter framework. Use worldToScreen to translate mathematical coordinates into on-screen pixels.

Implementation

@override
void paint(
  Canvas canvas,
  Size size,
  WorldToScreen worldToScreen,
  ScreenToWorld screenToWorld,
  double scale,
) {
  final point1 = worldToScreen(x1, y1);
  final point2 = worldToScreen(x2, y2);

  final linePaint = Paint()
    ..color = color
    ..strokeWidth = strokeWidth
    ..style = PaintingStyle.stroke
    ..strokeCap = StrokeCap.round;

  if (dashPattern != null) {
    drawDashedLine(canvas, point1, point2, linePaint);
  } else {
    canvas.drawLine(point1, point2, linePaint);
  }

  if (arrow) {
    drawArrowHead(canvas, point1, point2, linePaint);
  }
}