How to draw a half circle of rectangulars in flutter?

492

I have solved the problem. Below is my code:

Paint rectPaint = Paint()
      ..color = Colors.grey
      ..blendMode = BlendMode.darken
      ..style = PaintingStyle.fill;

    for (double angle = 180; angle >= 0; angle = angle - 6) {
      double angleInRadians = angle * math.pi / 180;

      double x = radius * math.cos(angleInRadians);
      double y = radius * math.sin(angleInRadians);
      y -= radius;
      y = -y;
      x += size.width / 2;
      canvas.save();
      canvas.translate(x, y + 27);
      canvas.rotate(-angleInRadians);
      canvas.drawRect(
          Rect.fromCenter(height: 4, width: 16, center: Offset(0, 0)),
          rectPaint);
      canvas.restore();
    }

Hope will be helpful for someone.

Share:
492
Ovidiu Uşvat
Author by

Ovidiu Uşvat

Updated on December 24, 2022

Comments

  • Ovidiu Uşvat
    Ovidiu Uşvat over 1 year

    I am trying to draw a half-circle made of custom shape not just a simple line.

    Here is an example of what I desire. I refer at gray rectangulars.

    enter image description here

    Is here anybody who knows how to do that? I would be greateful!

    • S.V.
      S.V. over 3 years
      Are you referring to doing something like using CustomPainter?
    • Ovidiu Uşvat
      Ovidiu Uşvat over 3 years
      Yes. I am new to canvas in Flutter and I need some help because i didn't find a satisfying tutorial or documentation.