[英]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.