1

当我尝试在列表视图中显示列表视图时遇到问题。现在它向我显示错误“垂直视口被赋予了无限的高度。”。我尝试添加一个容器并将高度设置为第二个列表视图,它可以工作。但我不想限制第二个列表视图的高度。

return new Scaffold(
    body: new Column(
        children: <Widget> [
          new Expanded(
            child: ListView(
              children: <Widget> [
                new Container(), // something else
                new ListView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    itemBuilder: (context, index) => new MenuCard(menuStore[index]),
                    itemCount: menuStore.length,
                    padding: new EdgeInsets.symmetric(vertical: 16.0)
                )
              ]
            )

          )
        ]
    )
);
4

3 回答 3

0

为了修复代码中的给定错误,您需要 shrinkWrap: true, in ListView.builderand ListView

 return new Scaffold(
        body: new Column(
            children: <Widget> [
              new Expanded(
                child: ListView(
                  shrinkWrap:ture,
                  children: <Widget> [
                    new Container(), // something else
                    new ListView.builder(
                        shrinkWrap:ture,
                        physics: NeverScrollableScrollPhysics(),
                        itemBuilder: (context, index) => new MenuCard(menuStore[index]),
                        itemCount: menuStore.length,
                        padding: new EdgeInsets.symmetric(vertical: 16.0)
                    )
                  ]
                )

              )
            ]
        )
    );
于 2019-10-17T20:28:48.120 回答
0

在此处尝试此答案,您可以使用ListView而不是GridView ,也可以从GridView中删除该属性。crossAxisCount

https://stackoverflow.com/a/53852317/3811162

于 2020-09-13T07:11:25.470 回答
0

您可能希望将ListView属性设置shrinkWraptrue

  /// Whether the extent of the scroll view in the [scrollDirection] should be
  /// determined by the contents being viewed.
  ///
  /// If the scroll view does not shrink wrap, then the scroll view will expand
  /// to the maximum allowed size in the [scrollDirection]. If the scroll view
  /// has unbounded constraints in the [scrollDirection], then [shrinkWrap] must
  /// be true.

...

  /// Defaults to false.
  final bool shrinkWrap;
于 2019-10-17T20:25:11.950 回答