[英]Flutter: ListView disable scrolling with touchscreen
是否可以让 ListView 只能通过 ScrollController 滚动,而不能通过触摸屏滚动?
正如评论中提到的, NeverScrollableScrollPhysics 类将执行以下操作:
NeverScrollableScrollPhysics 类
不允许用户滚动的滚动物理。
在 ListView 小部件中,使用
physics: const NeverScrollableScrollPhysics()
您可以只在 ListView 小部件中添加primary: false
默认为匹配平台约定。 此外,如果primary 为false,那么如果没有足够的内容可以滚动,用户将无法滚动,而如果primary 为true,他们总是可以尝试滚动。
更多内容请查看官方文档
启用和禁用滚动视图的条件语句。
physics: chckSwitch ? const NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
为我工作
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
...
NestedScrollView 呢?
bottomNavigationBar: _buildBottomAppBar(),
body: Container(
child: NestedScrollView(
physics: NeverScrollableScrollPhysics(),
controller: _scrollViewController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
buildSliverAppBar(innerBoxIsScrolled),
];
},
body: _buildBody(context),
),
),
);
它对我有用
您可以通过两种方式实现此目的
如果您只想禁用整个屏幕滚动
然后解决方案是将ListView
包装在IgnorePointer
小部件中。
你也可以像这样只在你的ListView
上禁用滚动
在 ListView 上设置shrinkWrap: true
和primary: true
属性,这将禁用滚动:
ListView( shrinkWrap: true, primary: true,
ListView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
Text('My temp data'),
Text('Wow its working'),
.
.
.
Text('My temp data'),
Text('Wow its working'),
Text('My temp data'),
Text('Wow its working'),
]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.