I want to a CustomPainter
that paints a triangle where the top edge is a bit rouned, like this:
I was able to paint a triangle with this:
class CustomStyleArrow extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Paint paint = Paint()
..color = Colors.white
..strokeWidth = 1
..style = PaintingStyle.fill;
final double triangleH = 10;
final double triangleW = 25.0;
final double width = size.width;
final double height = size.height;
final Path trianglePath = Path()
..moveTo(width / 2 - triangleW / 2, height)
..lineTo(width / 2, triangleH + height)
..lineTo(width / 2 + triangleW / 2, height)
..lineTo(width / 2 - triangleW / 2, height);
canvas.drawPath(trianglePath, paint);
final BorderRadius borderRadius = BorderRadius.circular(15);
final Rect rect = Rect.fromLTRB(0, 0, width, height);
final RRect outer = borderRadius.toRRect(rect);
canvas.drawRRect(outer, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
But I can not get the rounded corner. How can I do that?
Also, I the whole triangle should be as dynamic as possible so I can put it on top of any container and best case, also pass the location, where exactly the triangle should be.
With inspiration from k.s poyraz I got a perfect solution, where you can wrap any widget with an
ArrowIndicator
and place the arrow where ever you want: