如何在列表视图中显示列表视图
How to show the listview in a listview
我尝试在列表视图中显示列表视图时遇到问题。现在它向我显示错误 "Vertical viewport was given unbounded height."。我尝试添加一个容器并将高度设置为第二个列表视图并且它有效。但是我不想限制第二个列表视图的高度。
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)
)
]
)
)
]
)
);
您可能希望将 ListView
属性 shrinkWrap
设置为 true
:
/// 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;
为了修复代码中的给定错误,您需要在 ListView.builder
和 ListView
.
中 shrinkWrap: true
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)
)
]
)
)
]
)
);
在这里尝试这个答案,您可以使用 ListView 而不是 GridView,同时删除 crossAxisCount
属性 来自 GridView.
我尝试在列表视图中显示列表视图时遇到问题。现在它向我显示错误 "Vertical viewport was given unbounded height."。我尝试添加一个容器并将高度设置为第二个列表视图并且它有效。但是我不想限制第二个列表视图的高度。
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)
)
]
)
)
]
)
);
您可能希望将 ListView
属性 shrinkWrap
设置为 true
:
/// 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;
为了修复代码中的给定错误,您需要在 ListView.builder
和 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)
)
]
)
)
]
)
);
在这里尝试这个答案,您可以使用 ListView 而不是 GridView,同时删除 crossAxisCount
属性 来自 GridView.