如何在Flutter中检测ListView的滚动位置 [英] How to detect scroll position of ListView in Flutter
问题描述
我正在使用 ListView
小部件将项目显示为列表.在三个窗口中,查看项目必须将中间项目放置在中间.
I'm using ListView
widget to show items as a list. In a window three, items viewing must the middle item place in the middle.
那么在滚动停止时如何检测 ListView
的位置?
So how can I detect position of ListView
when scrolling stop?
如何检测ListView滚动停止?
How to detect ListView Scrolling stopped?
推荐答案
我使用了 NotificationListener
,它是一个小部件,用于监听气泡冒泡的通知.然后使用 ScrollEndNotification
,这表明滚动已停止.
I used NotificationListener
that is a widget that listens for notifications bubbling up the tree. Then use ScrollEndNotification
, which indicates that scrolling has stopped.
对于滚动位置,我使用了 _scrollController
,其类型为 ScrollController
.
For scroll position I used _scrollController
that type is ScrollController
.
new NotificationListener(
child: new ListView(
controller: _scrollController,
children: ...
),
onNotification: (t) {
if (t is ScrollEndNotification) {
print(_scrollController.position.pixels);
}
},
),
这篇关于如何在Flutter中检测ListView的滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!