【发布时间】:2018-11-01 19:40:34
【问题描述】:
是否可以让 ListView 只能使用 ScrollController 而不能使用触摸屏滚动?
【问题讨论】:
-
ListView中有一个字段
physics = NeverScrollableScrollPhysics();现在您可以根据某些条件实现它 -
你能多谈谈你尝试过的和没用的吗?
是否可以让 ListView 只能使用 ScrollController 而不能使用触摸屏滚动?
【问题讨论】:
physics = NeverScrollableScrollPhysics();现在您可以根据某些条件实现它
如 cmets 中所述,NeverScrollableScrollPhysics class 将执行此操作:
NeverScrollableScrollPhysics 类
不允许用户滚动的滚动物理特性。
【讨论】:
在 ListView 小部件中,使用
physics: const NeverScrollableScrollPhysics()
【讨论】:
您可以在 ListView 小部件中添加 primary: false
默认匹配平台约定。此外,如果primary为false,则如果内容不足,用户将无法滚动,而如果primary为true,则用户始终可以尝试滚动。
更多信息,请查看Official Doc
【讨论】:
启用和禁用滚动视图的条件语句。
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),
),
),
);
它对我有用
【讨论】: