简体   繁体   English

从 Firestore 获取数据后,如何使用 Flutter 创建线程评论?

[英]How to Create Threaded Comments using Flutter after getting data from Firestore?

I am developing a flutter application that can support threaded comments similar to Reddit, HackerNews.我正在开发一个 flutter 应用程序,它可以支持类似于 Reddit、HackerNews 的线程评论。

I am using Firestore.我正在使用 Firestore。 Here is the structure I am using now:这是我现在使用的结构:

Comment
    id
    parent_post_id
    parent_comment_id
    children_comment_id
    timeStamp
    author_id
    points

However, when I query for the comments using但是,当我使用查询评论时

firestore.collection('comments')
          .where('postID', isEqualTo: postID)
          .orderBy('createdAt', descending: true)

I get all the comments, including the replies but the replies of a comment are not placed directly under the parent comment.我收到所有评论,包括回复,但评论的回复不会直接放在父评论下。

I need the ability to rearrange the comments in the app after getting the data from Firestore and place the replies directly below their parents and arrange them according to date.我需要能够在从 Firestore 获取数据后重新排列应用程序中的评论,并将回复直接放在他们的父母下方并根据日期排列它们。 How can I go about doing this?我怎么能 go 关于这样做? Thanks.谢谢。

You will have to write code in your app to rearrange the query results after they become available in the app.您必须在应用程序中编写代码,以便在查询结果在应用程序中可用后重新排列它们。 Firestore really can't help you out with sorting on anything other than the contents of individual fields in their natural (or reverse) sort order.除了按自然(或反向)排序顺序对各个字段的内容进行排序之外,Firestore 确实无法帮助您对任何内容进行排序。 You can't instruct Firestore to interleave results based on other complex conditions.您不能指示 Firestore 根据其他复杂条件交错结果。

All of the sorting capabilities for Firestore is covered fully in the documentation , so you should review that to understand the limits. Firestore 的所有排序功能都在文档中完整介绍,因此您应该查看它以了解限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM