【问题标题】:How to draw a hexagon shape in flutter?如何在颤动中绘制六边形?
【发布时间】:2021-05-12 12:36:28
【问题描述】:

我想画一个六边形,但我做不到。 这是我的结果:

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;
  }

我希望是这样的:

【问题讨论】:

    标签: flutter paint


    【解决方案1】:

    去这个网站https://fluttershapemaker.com很简单

    【讨论】:

      【解决方案2】:

      你可以试试这个,polygon_clipperflutter_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),
          ),
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多