问题描述
我有一个这样的小部件树:
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:是的,物理:NeverScrollableScrollPhysics()
,但是构建收缩包装的列表视图比构建普通的列表视图更昂贵,我认为在列表上使用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内,但防止它们单独滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!