如何检查滚动位置是在 ListView 的顶部还是底部? [英] How to check if scroll position is at top or bottom in ListView?
问题描述
我正在尝试实现无限滚动功能.
我尝试在 NotificationListener
内部使用 ListView
来检测滚动事件,但是我看不到显示滚动是否到达底部的事件查看.
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屋!