简体   繁体   English

底部溢出 80 像素的 RenderFlex

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

The page got an error "A RenderFlex overflowed by 80 pixels on the bottom".该页面出现错误“RenderFlex 在底部溢出 80 像素”。 How can you fix it?你怎么能修好它?

 class FavNews extends StatelessWidget { final FavoritesController controller = Get.find(); FavNews({Key? key}): super(key: key); @override Widget build(BuildContext context) { return Obx(() { return SizedBox( height: MediaQuery.of(context).size.height, child: ListView.builder( itemCount: controller.news.length, itemBuilder: (BuildContext context, int index) { return FavNewsItem( article: controller.news.keys.toList()[index], index: index, ); }), ); }); } }

在此处输入图像描述

Put it Sizedbox inside a SingleChildScrollView widget.将其 Sizedbox 放在 SingleChildScrollView 小部件中。

 return SingleChildScrollView(
     child: SizedBox(
       height: MediaQuery.of(context).size.height,
       child: ListView.builder(
        itemCount: controller.news.length,
        itemBuilder: (BuildContext context, int index) {
          return FavNewsItem(
            article: controller.news.keys.toList()[index],
            index: index,
          );
        }),)

Just try it.就试一试吧。 It may work它可能有效

The issue is with the height of your SizedBox.问题在于您的 SizedBox 的高度。
MediaQuery.of(context).size.height return the height of your entire screen including statusbar, appbar and system gestires at the bottom. MediaQuery.of(context).size.height返回整个屏幕的高度,包括底部的状态栏、应用栏和系统手势。

With ListView.builder you can use shrinkWrap: true that will use only the space that it acutally need to use.使用ListView.builder ,您可以使用shrinkWrap: true ,它只会使用它实际需要使用的空间。

Example:例子:

return SingleChildScrollView(
  child: ListView.builder(
            shrinkWrap: true,
            itemCount: controller.news.length,
            itemBuilder: (BuildContext context, int index) {
              return FavNewsItem(
                article: controller.news.keys.toList()[index],
                index: index,
              );
            }),
         ),
   );

do not hardcoat the height while using the scrollbar remove the height attribute and it'll work just fine使用滚动条时不要硬涂高度删除高度属性,它会工作得很好

  final FavoritesController controller = Get.find();

  FavNews({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return SizedBox(
        child: ListView.builder(
            itemCount: controller.news.length,
            itemBuilder: (BuildContext context, int index) {
              return FavNewsItem(
                article: controller.news.keys.toList()[index],
                index: index,
              );
            }),
      );
    });
  }
}```

you do not need sizedBox你不需要sizedBox

return Obx(() {
return ListView.builder(
        srinkWrap: true;
        itemCount: controller.news.length,
        itemBuilder: (BuildContext context, int index) {
          return FavNewsItem(
            article: controller.news.keys.toList()[index],
            index: index,
          );
        }),);
}

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

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