drawAnnotationLine function
void
drawAnnotationLine()
Helper to draw a dashed line on a canvas.
Implementation
void drawAnnotationLine(
Canvas canvas,
Offset start,
Offset end,
Paint paint,
List<double>? dashPattern,
) {
if (dashPattern == null || dashPattern.isEmpty) {
canvas.drawLine(start, end, paint);
} else {
final dx = end.dx - start.dx;
final dy = end.dy - start.dy;
final distance = math.sqrt(dx * dx + dy * dy);
if (distance == 0) return;
final unitDx = dx / distance;
final unitDy = dy / distance;
var current = 0.0;
var dashIndex = 0;
var isDrawing = true;
while (current < distance) {
final dashLength = dashPattern[dashIndex % dashPattern.length];
final nextCurrent = (current + dashLength).clamp(0.0, distance);
if (isDrawing) {
canvas.drawLine(
Offset(start.dx + unitDx * current, start.dy + unitDy * current),
Offset(
start.dx + unitDx * nextCurrent, start.dy + unitDy * nextCurrent),
paint,
);
}
current = nextCurrent;
dashIndex++;
isDrawing = !isDrawing;
}
}
}