有没有可能让 ListView 仅通过滚动控制器来滚动,而不使用触摸屏幕?
如评论中所提到的,NeverScrollableScrollPhysics 类 可以实现此功能:
NeverScrollableScrollPhysics 类
不允许用户滚动的滚动物理效果。
physics: const NeverScrollableScrollPhysics()
您可以在ListView Widget中使用primary: false
来设置。
默认匹配平台惯例。此外,如果primary为false,则当内容不足以滚动时,用户无法滚动,而如果primary为true,则他们始终可以尝试滚动。
更多信息,请查看官方文档
启用和禁用滚动视图的条件语句。
physics: chckSwitch ? const NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
对我来说起作用了
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
...
bottomNavigationBar: _buildBottomAppBar(),
body: Container(
child: NestedScrollView(
physics: NeverScrollableScrollPhysics(),
controller: _scrollViewController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
buildSliverAppBar(innerBoxIsScrolled),
];
},
body: _buildBody(context),
),
),
);
对我来说它起作用了。
physics = NeverScrollableScrollPhysics()
;现在你可以根据某些条件来实现它。 - Tree