Flutter:如何避免ListView动态滚动(或更改其物理特性) [英] Flutter: How to avoid ListView to scroll (or change its physics) dynamically
问题描述
我有一个 ListView 小部件,我希望允许它是可滚动的还是基于某种逻辑的.
I have a ListView widget and i would like to allow it to be scrollable or not based on some logic.
NeverScrollableScrollPhysics 阻止滚动,但是由于物理参数是最终的之后就无法更改.
NeverScrollableScrollPhysics prevents scrolling, but since physics parameter is final i can't change it afterwards.
我本以为可以使用状态来通过不同的物理学来重建ListView,但是我想这是一个相当繁重的操作,可以重建整个ListView.
I thought to use state to rebuild the ListView using different physics, but i guess is a quite heavy operation to rebuild the entirely ListView.
有人知道或如何处理这种情况,在这种情况下,用户在完成其他用户操作之前不应该滚动ListView?
Does anyone knows or how to deal with this situation, where the user should not scroll a ListView until other user action got accomplished?
推荐答案
您可以在ListView中有条件地应用物理学:
You can apply the physics conditionally in your ListView:
shrinkWrap: true,
physics: !isScrolable? const NeverScrollableScrollPhysics():
const AlwaysScrollableScrollPhysics(),
然后,在需要时可以更改状态以修改变量的值.
Then when you need you can change the state modifying the value of your variable.
setState(() {
isScrolable = !isScrolable;
});
这篇关于Flutter:如何避免ListView动态滚动(或更改其物理特性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!