如何在Flutter中的分组ListView中滚动到自定义索引?

huangapple go评论57阅读模式
英文:

how to scroll to custom index in grouped listview in flutter?

问题

我想创建一个聊天页面,在这个页面上有两个列表,第一个列表是日期,第二个列表是在这个日期上的消息(分组列表),就像这张图片一样:

如何在Flutter中的分组ListView中滚动到自定义索引?

我创建了这个,但我想要实现回复功能,用户点击消息,滚动到被回复的消息。我在实现这个功能时遇到了问题,因为我有两个列表!我使用了scroll_to_index包,但不适用于两个列表(至少我没能实现)。我尝试获取每个项目的高度,以找到位置并滚动到位置,但无法为ListView中的每个项目设置GlobalKey以获取小部件的大小。有人知道如何实现这个吗?

英文:

I want to create chat page, in this page I have two list, first list is date and second list is message on this date(group list),like this image

如何在Flutter中的分组ListView中滚动到自定义索引?

I create this, but I want implement reply function, that user click on message, scroll to replied message.
I have problem to implement this, because I have two list!
I use scroll_to_index package,but not suitable for two list(At least I couldn't)
I try get height of each item, to find position and scroll to position, but can't set Globalkey for each item in ListView to get size of widget.
anyone knows to implement this?

答案1

得分: 1

我遇到了和你一样的问题,但我使用的包是 grouped_list,我找到了一个基于 grouped_list 和 scrollable_positioned_list 的这个包。使用这个包,你可以滚动到回复文本的位置。我觉得这应该能解决你的问题。sticky_grouped_list 是一个可以将列表项分组到部分的 ListView。它基于 scrollable_positioned_list,可以通过编程方式滚动列表到特定位置。你可以在 pub.dev 上查看详情。

sticky_grouped_list
scrollable_positioned_list

英文:

I had the same issue you faced, unlike you the package I was using was grouped_list and I found this package. Which is based on grouped_list and scrollable_positiined_list. Using this package You can scroll to the position of the replied text. I think this should solve your problem. sticky_grouped_list
A ListView in which list items can be grouped to sections. Based on scrollable_positioned_list, which enables Programatically scrolling of the list to a specific position. You can see the detail in pub.dev

huangapple
  • 本文由 发表于 2023年2月16日 19:02:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471313.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定