Ovidiu Uşvat
Ovidiu Uşvat

Reputation: 823

How to draw a half circle of rectangulars in flutter?

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!

Upvotes: 3

Views: 1040

Answers (1)

Ovidiu Uşvat
Ovidiu Uşvat

Reputation: 823

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.

Upvotes: 3

Related Questions