Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created December 19, 2021 07:44
Show Gist options
  • Save pingbird/b8ddbeee09a2e8e054a2116dc4ec79c4 to your computer and use it in GitHub Desktop.
Save pingbird/b8ddbeee09a2e8e054a2116dc4ec79c4 to your computer and use it in GitHub Desktop.
void _paintArrow(
Canvas canvas, {
required Color color,
required Offset offset,
required double angle,
double length = 12.0,
}) {
final height = length * (sqrt(3) / 2);
final top = Offset(0, -height / 2);
final left = Offset(-length / 2, height / 2);
final right = Offset(length / 2, height / 2);
final leftFace = Offset.lerp(top, left, 0.5)!;
final rightFace = Offset.lerp(top, right, 0.5)!;
final bottomFace = Offset.lerp(left, right, 0.5)!;
final path = Path()
..moveTo(leftFace.dx, leftFace.dy)
..cubicTo(top.dx, top.dy, top.dx, top.dy, rightFace.dx, rightFace.dy)
..cubicTo(
right.dx, right.dy, right.dx, right.dy, bottomFace.dx, bottomFace.dy)
..cubicTo(left.dx, left.dy, left.dx, left.dy, leftFace.dx, leftFace.dy)
..close();
canvas.save();
canvas.translate(offset.dx, offset.dy);
canvas.rotate(angle + pi);
canvas.drawPath(
path,
Paint()
..color = color
..strokeJoin = StrokeJoin.round,
);
canvas.restore();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment