Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

space between flutter cards

i am trying to find out why there is a big space or gab between those two flutter cards. i know there is something wrong here with the code. i checked out other posts on stackoverflow but nothing i have found could help me out, any help please. thanks

enter image description here

here is my code down below..

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',
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
question from:https://stackoverflow.com/questions/65941988/space-between-flutter-cards

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try changing the child Aspect Ratio in your GridView =>

this ====>>>

childAspectRatio: (itemWidth / itemHeight),

to be like that for example

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]),
                  ),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...