如何检查滚动位置是在ListView的顶部还是底部? [英] How to check if scroll position is at top or bottom in ListView?
问题描述
我正在尝试实现无限滚动功能.
我尝试在NotificationListener
上使用内部的ListView
来检测Scroll事件,但是看不到表明滚动是否到达视图底部的事件.
I tried using a ListView
inside on a NotificationListener
to detect Scroll events, but I can't see an event that says if the scroll has reached the bottom of the view.
哪种方法是实现这一目标的最佳方法?
Which would be the best way to achieve this?
推荐答案
您可以使用ListView.builder
创建具有无限项的滚动列表.当显示新单元格时,将根据需要调用您的itemBuilder
.
You can use a ListView.builder
to create a scrolling list with unlimited items. Your itemBuilder
will be called as needed when new cells are revealed.
如果希望收到有关滚动事件的通知,以便可以从网络上加载更多数据,则可以传递controller
自变量,并使用addListener
将侦听器附加到ScrollController
. ScrollController
的position
可用于确定滚动是否接近底部.
If you want to be notified about scroll events so you can load more data off the network, you can pass a controller
argument and use addListener
to attach a listener to the ScrollController
. The position
of the ScrollController
can be used to determine whether the scrolling is close to the bottom.
这篇关于如何检查滚动位置是在ListView的顶部还是底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!