Anvar Quvandiqov
Anvar Quvandiqov

Reputation: 289

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

Upvotes: 1

Views: 5907

Answers (2)

Jim
Jim

Reputation: 7601

you can try this, polygon_clipper with flutter_neumorphic

Neumorphic(
  style: NeumorphicStyle(
    depth: -5,
    lightSource: LightSource.topLeft,
    color: Colors.grey
  ),
  child:
    ClipPolygon(  
     sides: 6, 
     borderRadius: 5.0, // Default 0.0 degrees
     rotate: 90.0, // Default 0.0 degrees
     boxShadows: [  
      PolygonBoxShadow(color: Colors.black, elevation: 1.0),
      PolygonBoxShadow(color: Colors.grey, elevation: 5.0)
     ],
     child: Container(color: Colors.black),
    ),
)

Upvotes: 2

Ardeshir ojan
Ardeshir ojan

Reputation: 2419

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

Upvotes: 5

Related Questions