gridview生成器,其项在抖动中具有随机宽度

问题描述 投票:0回答:1

我需要显示这样的内容enter image description here

有人可以帮忙吗?我可以实现以下输出

enter image description here我正在使用以下代码::

GridView.builder(

          scrollDirection: Axis.vertical,
          physics: ScrollPhysics(),
          shrinkWrap: true,
          itemCount: 6,
          gridDelegate:
              SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2,
                childAspectRatio: MediaQuery.of(context).size.width /
                  (MediaQuery.of(context).size.height / 4),),
          itemBuilder: (BuildContext context, int index) {

            return GestureDetector(
              child: Container(

                padding: EdgeInsets.all(0.0),
                margin: EdgeInsets.only(
                    left: 10.0, right: 10.0, top: 10.0, bottom: 10.0),
                decoration: BoxDecoration(
                  border: Border.all(color: Color(0xFF282f61),width: 2.0),
                  borderRadius: BorderRadius.all(Radius.circular(
                      14.0) //                 <--- border radius here
                  ),
                ),
                child:    Center(
                  child: Text(
                      'Avg-project',
                      style: TextStyle(
                        color: Color(0xFF17b01b),
                        fontSize: 14.0,
                      ),
                  ),
                ),
              ),
              onTap: () {},
            );
          },
        ))

我如何在抖动中获得具有随机宽度的gridview?

flutter flutter-layout
1个回答
0
投票

尝试一下,

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BackAppBar("Notifications", context),
      body: Wrap(
        children: [
          "Help Moviing",
          "Furniture Assembly",
          "Mounting",
          "Home Repairs",
          "Personal Assistant",
          "Delivery",
          "Hard Work",
          "Practice & Unpacking",
          "Painting",
          "Cleaning",
          "Heavy Liffing"
        ].map((f) => GestureDetector(
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
                    margin: EdgeInsets.only(
                        left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
                    decoration: BoxDecoration(
                      border: Border.all(color: Color(0xFF282f61), width: 2.0),
                      borderRadius: BorderRadius.all(Radius.circular(
                          10.0) //                 <--- border radius here
                          ),
                    ),
                    child: Text(f,
                      style: TextStyle(
                        color: Color(0xFF17b01b),
                        fontSize: 16.0,
                      ),
                    ),
                  ),
                  onTap: () {},
                ))
            .toList(),
      ),
    );
  } 

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.