英文:
How to keep at the current Scroll position in ListView.builder without any auto scroll when new items added
问题
使用情况:我正在制作聊天页面的分页,将"reverse"设置为false,并且当用户向上滚动以加载更多项目时,滚动会自动跳转到0偏移量,如何防止这种情况发生?我希望无论添加了什么项目,都能保持在当前位置。
我对这个问题进行了很多研究,找到的解决方案场景如下:
-
将"reverse"设置为true:但这不适用于我的情况,因为我还有双向分页
-
计算添加项目前后的高度差:但我发现这太复杂了,而且不总是准确的(如果有准确的计算方法,请分享)
有没有解决这个非常恼人行为的解决方案?
英文:
the use case : i am making pagination in chat page, the reverse set to false , and when user scroll up to load more items the scroll auto jump to 0 offset , How to prevent it ? i want like whatever items added so want to stay at the same current position .
I researched a lot about this problem and the solution scenarios I found like following
-
reverse set to true : but this not suite my case because i also have two side pagination too
-
Calculate the height difference between before and after items added : but i found this so
complicated And not always accurate (Any accurate calculation for this thing, please share)
any solution guys with this very annoying behavior?
答案1
得分: 1
如果您正在使用ListView.builder
小部件中的key
属性,请尝试跳过该属性。我遇到了同样的问题,并使用这种方式解决了它。这样,在添加新项目时,它会保持其位置。
英文:
If you are using the key
attribute inside your ListView.builder
widget. Try skipping that attribute. I was having the same problem and fixed it using this. In this way, it keeps its position when new items are added.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论