Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round Arc edges in flutter?

Tags:

canvas

flutter

I need to create an arc chart as following:

enter image description here

Using canvas I've created this one:

enter image description here

My code:

class CustomChartPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {

    Rect drawingRect = Rect.fromCircle(center: Offset(size.width / 2, size.height / 2), radius: size.width / 2);


    final Paint paint2 = Paint();
    paint2.color = const Color.fromRGBO(0, 0, 0, 0.04);
    paint2.style = PaintingStyle.stroke;
    paint2.strokeWidth = 50;

    canvas.drawCircle(Offset(size.width / 2, size.height / 2), size.width / 2, paint2);

    canvas.drawArc(drawingRect,
        -pi / 2 + 0.35,
        pi - 0.35,
        false,
        greenPaint);

    canvas.drawArc(drawingRect,
        pi / 2 + 0.35,
        pi - 0.35,
        false,
        orangePaint);
  }
}

How can I round edges of arcs as presented on the first picture?

like image 761
alectogeek Avatar asked Feb 06 '20 08:02

alectogeek


1 Answers

As @pskink mentioned, the solution is to use Paint.strokeCap, more precisely: paint.strokeCap = StrokeCap.round

like image 152
alectogeek Avatar answered Oct 01 '22 16:10

alectogeek