简体   繁体   English

底部溢出 125 个像素的 RenderFlex

[英]A RenderFlex overflowed by 125 pixels on the bottom

I am building a Flutter ecommerce app for delivery beverages.我正在构建一个用于配送饮料的 Flutter 电子商务应用程序。 I am having an issue with my wishlist page.我的愿望清单页面有问题。 I am getting an error where it says "a Renderflex overflowed by 125 pixels at the bottom".我收到一个错误,上面写着“Renderflex 在底部溢出了 125 个像素”。 The error is saying it is caused by the Column widget.I have tried different approaches including an Expanded widget as well as a Sizebox widget but with no luck.错误是说它是由 Column 小部件引起的。我尝试了不同的方法,包括 Expanded 小部件和 Sizebox 小部件,但没有运气。 Please can anyone assist.请任何人都可以提供帮助。

在此处输入图像描述

This shows that it is overflowed by 125 pixels at the bottom这表明它在底部溢出了125个像素

在此处输入图像描述

Here's the code that's causing the error:这是导致错误的代码:

Container(
                height: 1500.0,
                width: double.infinity,
                child: Column(
                  children: [
                    const Text(
                      'My Favourites',
                      style: TextStyle(fontSize: 40.0),
                    ),
                    GridView.builder(
                      shrinkWrap: true,
                      itemCount: favItems.length,
                      itemBuilder: ((context, index) {
                        return ProductItem(
                            id: favItems[index].id,
                            bottleName: favItems[index].bottleName,
                            imgUrl: favItems[index].image,
                            price: favItems[index].price,
                            bottle: favItems[index]);
                      }),
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 2,
                        childAspectRatio: itemWidth / itemHeight,
                      ),
                    ),
                  ],
                ),
              ));

Wrap the GridView.builder with the Flexible widget.使用灵活小部件包装 GridView.builder。 Column throws an exception because it doesn't know the height of the GridView列抛出异常,因为它不知道 GridView 的高度

Container(
  height: 1500.0,
  width: double.infinity,
  child: Column(
    children: [
      const Text(
        'My Favourites',
        style: TextStyle(fontSize: 40.0),
      ),
      Flexible(child: 
        GridView.builder(
          shrinkWrap: true,
          itemCount: favItems.length,
          itemBuilder: ((context, index) {
            return ProductItem(
              id: favItems[index].id,
              bottleName: favItems[index].bottleName,
              imgUrl: favItems[index].image,
              price: favItems[index].price,
              bottle: favItems[index]);
          }),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: itemWidth / itemHeight,
          ),
        )),
    ],
  ),
));

Wrap the grid view builder with Expanded widget and it will work fine用 Expanded 小部件包装网格视图构建器,它将正常工作

Wrap your GridView.builder( with Expanded( it will work for you.包装你的GridView.builder(Expanded(它会为你工作。

Container(
                  height: 1500.0,
                  width: double.infinity,
                  child: Column(
                    children: [
                      const Text(
                        'My Favourites',
                        style: TextStyle(fontSize: 40.0),
                      ),
                      Expanded(
                        child: GridView.builder(
                          shrinkWrap: true,
                          itemCount: favItems.length,
                          itemBuilder: ((context, index) {
                            return ProductItem(
                                id: favItems[index].id,
                                bottleName: favItems[index].bottleName,
                                imgUrl: favItems[index].image,
                                price: favItems[index].price,
                                bottle: favItems[index]);
                          }),
                          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 2,
                            childAspectRatio: itemWidth / itemHeight,
                          ),
                        ),
                      ),
                    ],
                  ),
                )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM