Search code examples
flutterpaint

How to draw a hexagon shape in flutter?


I wanted to draw a hexagon shape but I couldn't do what I wanted. this is my result:

Path createHexagonPath() {
    const int SIDES_OF_HEXAGON = 6;
    const double radius = 50;
    const Offset center = Offset(50, 50);
    final path = Path();
    var angle = (pi * 2) / SIDES_OF_HEXAGON;
    Offset firstPoint = Offset(radius * cos(0.0), radius * sin(0.0));
    path.moveTo(firstPoint.dx + center.dx, firstPoint.dy + center.dy);
    for (int i = 1; i <= SIDES_OF_HEXAGON; i++) {
      double x = radius * cos(angle * i) + center.dx;
      double y = radius * sin(angle * i) + center.dy;
      path.lineTo(x, y);
    }
    path.close();
    return path;
  }

enter image description here

I want that to be the case:

enter image description here


Solution

  • go over to this website https://fluttershapemaker.com it is simple and easy