当我将ListView放在扩展中时出现RenderBox错误

时间:2020-07-01 05:46:49

标签: flutter listview dart

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

方法'>'在null上被调用。接收方:null尝试呼叫:

(1e-10)相关的引起错误的小部件是:行

代码是:

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

我想要身高

1 个答案:

答案 0 :(得分:1)

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