颤振卡之间的空间

时间:2021-01-28 17:13:03

标签: flutter

我试图找出为什么这两张颤动卡之间有一个很大的空间或缝隙。我知道代码有问题。我查看了 stackoverflow 上的其他帖子,但我没有发现任何可以帮助我的帖子,请提供任何帮助。谢谢

enter image description here

下面是我的代码..

Container(
              child: GridView.builder(
                padding: EdgeInsets.zero,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 1,
                ),
                shrinkWrap: true,
                physics: ScrollPhysics(),
                itemCount: promoList.length,
                itemBuilder: (BuildContext context, int index) =>
                    PromotionCard(promotion: promoList[index]),
              ),
            )


@override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Card(
          margin: EdgeInsets.all(0.0),
          elevation: 2.0,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10.0),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              ClipRRect(
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(8.0),
                  topRight: Radius.circular(8.0),
                ),
                child: Image.asset(
                  promotion.imageUrl,
                  fit: BoxFit.cover,
                  width: MediaQuery.of(context).size.width,
                ),
              ),
              Padding(
                padding: EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0),
                child: Text(
                  promotion.title,
                  style: TextStyle(
                    fontSize: 16.0,
                    fontFamily: 'BuffetRegular',
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

1 个答案:

答案 0 :(得分:1)

尝试更改 GridView 中的子长宽比 =>

这个====>>>

childAspectRatio: (itemWidth / itemHeight),

例如像那样

GridView.builder(
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                      crossAxisCount: 1,
                    ),
                    childAspectRatio: (100/ 100),

                    shrinkWrap: true,
                    //physics: ScrollPhysics(),
                    itemCount: promoList.length,
                    itemBuilder: (BuildContext context, int index) =>
                        PromotionCard(promotion: promoList[index]),
                  ),