[英]Flutter: ListView disable scrolling with touchscreen
Is it possible to let a ListView only be scrollable with the ScrollController and not with the touchscreen?是否可以让 ListView 只能通过 ScrollController 滚动,而不能通过触摸屏滚动?
As mentioned in the comments, the NeverScrollableScrollPhysics class will do this:正如评论中提到的, NeverScrollableScrollPhysics 类将执行以下操作:
NeverScrollableScrollPhysics class
NeverScrollableScrollPhysics 类
Scroll physics that does not allow the user to scroll.
不允许用户滚动的滚动物理。
在 ListView 小部件中,使用
physics: const NeverScrollableScrollPhysics()
You may add just primary: false
inside your ListView Widget您可以只在 ListView 小部件中添加
primary: false
Defaults to matching platform conventions.默认为匹配平台约定。 Furthermore, if the primary is false, then the user cannot scroll if there is insufficient content to scroll, while if the primary is true, they can always attempt to scroll.
此外,如果primary 为false,那么如果没有足够的内容可以滚动,用户将无法滚动,而如果primary 为true,他们总是可以尝试滚动。
For more, check outOfficial Doc更多内容请查看官方文档
启用和禁用滚动视图的条件语句。
physics: chckSwitch ? const NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
Worked for me为我工作
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
...
what about NestedScrollView ? NestedScrollView 呢?
bottomNavigationBar: _buildBottomAppBar(),
body: Container(
child: NestedScrollView(
physics: NeverScrollableScrollPhysics(),
controller: _scrollViewController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
buildSliverAppBar(innerBoxIsScrolled),
];
},
body: _buildBody(context),
),
),
);
it's working for me它对我有用
You can achieve this by two ways您可以通过两种方式实现此目的
If you just want to disable scrolling entirely screen如果您只想禁用整个屏幕滚动
Then solution is to wrap the ListView
in an IgnorePointer
widget.然后解决方案是将
ListView
包装在IgnorePointer
小部件中。
And you can also disable scrolling only on your ListView
like this你也可以像这样只在你的
ListView
上禁用滚动
set the shrinkWrap: true
and primary: true
property on the ListView, which will disable scrolling:在 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.