【问题标题】:How to create Hexagon shape Container with flutter same this photo如何用颤振创建六边形容器与这张照片相同
【发布时间】:2022-01-22 06:35:05
【问题描述】:

如何创建与这张照片相同的六边形容器

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    可以使用Stack 和Container's decoration 使用bottomLeft 进行归档。

    
    class AWT extends StatefulWidget {
      AWT({Key? key}) : super(key: key);
    
      @override
      _AWTState createState() => _AWTState();
    }
    
    class _AWTState extends State<AWT> {
      final border = const BorderRadius.only(
        bottomLeft: Radius.circular(140),
      );
    
      clickTest(int index) => OutlinedButton(
          onPressed: () {
            print("tap Event from $index");
          },
          child: Text("Click test"));
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.black,
          appBar: AppBar(
            backgroundColor: Colors.pink.shade100,
            elevation: 0,
          ),
          body: LayoutBuilder(
            builder: (context, constraints) {
              final boxheight = constraints.maxHeight / 6;
              return Stack(
                children: [
                  //4th container
                  Container(
                    height: (boxheight * 4) + kToolbarHeight,
                    alignment: Alignment.bottomCenter,
                    decoration: BoxDecoration(
                      color: Colors.deepPurple,
                      borderRadius: border,
                    ),
                    child: clickTest(4),
                  ), //3rd container
                  Container(
                    height: (boxheight * 3) + kToolbarHeight,
                    alignment: Alignment.bottomCenter,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: border,
                    ),
                    child: clickTest(3),
                  ), //second container
                  Container(
                    height: (boxheight * 2) + kToolbarHeight,
                    alignment: Alignment.bottomCenter,
                    decoration: BoxDecoration(
                      color: Colors.pink.shade300,
                      borderRadius: border,
                    ),
                    child: clickTest(2),
                  ),
                  // top container
                  Container(
                    alignment: Alignment.bottomCenter,
                    height: boxheight,
                    decoration: BoxDecoration(
                      color: Colors.pink.shade100,
                      borderRadius: border,
                    ),
                    child: clickTest(1),
                  ),
                ],
              );
            },
          ),
        );
      }
    }
    

    【讨论】:

    • 请分享完整代码
    • 补充,我正在使用constraints测量并提供高度
    猜你喜欢
    • 1970-01-01
    • 2021-12-14
    • 2021-10-15
    • 2021-11-19
    • 2022-11-23
    • 2022-01-24
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多