draw method

  1. @override
void draw(
  1. Canvas canvas,
  2. Size size,
  3. double scaleX,
  4. double scrollX,
  5. double getX(
    1. double
    ),
  6. double getY(
    1. double
    ),
)
override

Implementation

@override
void draw(Canvas canvas, Size size, double scaleX, double scrollX,
    double Function(double) getX, double Function(double) getY) {
  if (startPoint == null || directionPoint == null) return;

  final paint = Paint()
    ..color = color
    ..strokeWidth = strokeWidth
    ..style = PaintingStyle.stroke;

  // 计算射线方向
  final direction = (directionPoint! - startPoint!).direction;
  final length = size.width + size.height; // 足够长的射线

  // 绘制射线
  final endPoint = startPoint! + Offset.fromDirection(direction, length);
  canvas.drawLine(startPoint!, endPoint, paint);
}