Is it possible to let a ListView only be scrollable with the ScrollController and not with the touchscreen?
As mentioned in the comments, the NeverScrollableScrollPhysics class will do this:
NeverScrollableScrollPhysics class
Scroll physics that does not allow the user to scroll.
在 ListView 小部件中,使用
physics: const NeverScrollableScrollPhysics()
You may add just primary: false
inside your ListView Widget
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.
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 ?
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.
And you can also disable scrolling only on your ListView
like this
set the shrinkWrap: true
and primary: true
property on the ListView, which will disable scrolling:
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'),
]
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.