如果页面没有超出屏幕大小,是否可以禁用 ListView 滚动?
我总是使用 ListView 来避免溢出屏幕,但是当页面的内容小于屏幕时,我可以看到结束滚动动画,在这种情况下如何禁用滚动,并且如果屏幕大小能够滚动小吗??
最佳答案
我认为最好的方法是使用 SingleChildScrollView :
This widget is useful when you have a single box that will normally be entirely visible, for example a clock face in a time picker, but you need to make sure it can be scrolled if the container gets too small in one axis (the scroll direction).
而不是使用 ListView
只需使用 Column
并将其放在 SingleChildScrollView
内:
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[/**/],
),
)
或者如果你出于某种原因需要使用ListView
,你可以使用shrinkWrap
和NeverScrollableScrollPhysics
:
SingleChildScrollView(
child: ListView(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: <Widget>[/**/],
),
)
关于flutter - 禁用 ListView 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57246120/