getDashedPath method
Path
getDashedPath(
{ - required Offset a,
- required Offset b,
- required dynamic gap,
})
Implementation
Path getDashedPath({
required Offset a,
required Offset b,
required gap,
}) {
Size size = Size(b.dx - a.dx, b.dy - a.dy);
Path path = Path();
path.moveTo(a.dx, a.dy);
bool shouldDraw = true;
math.Point currentPoint = math.Point(a.dx, a.dy);
num radians = math.atan(size.height / size.width);
num dx = math.cos(radians) * gap < 0
? math.cos(radians) * gap * -1
: math.cos(radians) * gap;
num dy = math.sin(radians) * gap < 0
? math.sin(radians) * gap * -1
: math.sin(radians) * gap;
while (currentPoint.x <= b.dx && currentPoint.y <= b.dy) {
shouldDraw
? path.lineTo(currentPoint.x as double, currentPoint.y as double)
: path.moveTo(currentPoint.x as double, currentPoint.y as double);
shouldDraw = !shouldDraw;
currentPoint = math.Point(
currentPoint.x + dx,
currentPoint.y + dy,
);
}
return path;
}