如何在 SingleChildScrollView 中放置一个列表视图但防止它们单独滚动? [英] how to place a listview inside a SingleChildScrollView but prevent them from scrolling separately?
问题描述
我有一个像这样的小部件树:
I have a widget tree like this:
SingleChildScrollView
Column
Container
ListView(or GridView)
问题是当我的小部件树像上面那样时,它给了我
the problem is that when my widget tree is like above, it gives me error of
需要油漆
所以我像这样改变我的小部件树:
so I change my widget tree like this:
Column
Container
ListView(or GridView)
但在这种情况下,ListView 或 GridView 部分分别滚动,我希望整个小部件树滚动.你认为我如何才能实现它?
but in this situation the ListView or GridView part scrolls separately, and I want the whole widget tree to scroll. how do you think I can achieve it?
推荐答案
正如其他答案所建议的,您可以通过设置 shrinkWrap: true, Physics: NeverScrollableScrollPhysics()
来实现,但构建一个shrinkwrappedlistview 比构建一个普通的 listview 成本更高,我认为在列表上使用 map() 会是一个好主意.
As suggested by other answers, you can do that by setting shrinkWrap: true, physics: NeverScrollableScrollPhysics()
, but building a shrinkwrapped listview is more expensive than building a normal listview, I think it will be a good idea to use a map() on the list.
Column(
children: <Widget>[
...itemList.map((item) {
return Text(item);
}).toList(),
],
),
这篇关于如何在 SingleChildScrollView 中放置一个列表视图但防止它们单独滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!