首页 > 解决方案 > 当我的 ListView 在展开时出现 RenderBox 错误

问题描述

我遵循了其他解决方案,其中用户将 ListView 放入展开后,然后将展开后放入 SizedBox,然后将 SizedBox 放入一行。我仍然收到渲染框错误。

在 null 上调用了方法“>”。接收者:null 尝试调用:

(1e-10) 相关的导致错误的小部件是:Row

代码是:

 return new Row(children: [
              new Expanded(
                child: SizedBox(
                  width: double.infinity,
                  child: ListView(
                physics: const AlwaysScrollableScrollPhysics(),
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                children: getPostItems(snapshot),
              ))
              )]);

我想要身高

标签: flutterlistviewdart

解决方案


double.infinity用于使元素的长度与父元素的长度相同。在示例中,SizedBox试图与 的宽度相同Row,后者是根据子级扩展的 Widget,其宽度无限。试试这个:

Expanded(
  child: Container( // This way, the Container should fit into a non infinite width or height, but rather the dimensions of the remaining space of another widget
    child: ListView(
      physics: const AlwaysScrollableScrollPhysics(),
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      children: getPostItems(snapshot),
    )
  )
)

推荐阅读