Firebase 如何根据flifter中的时间戳对Firestore流进行排序

Firebase 如何根据flifter中的时间戳对Firestore流进行排序,firebase,flutter,sorting,google-cloud-firestore,stream-builder,Firebase,Flutter,Sorting,Google Cloud Firestore,Stream Builder,我正在尝试使用flutter中的streambuilder生成一个列表,并希望根据firestore时间戳对该列表进行排序。我已经尝试了下面给出的代码 ```stream: FirebaseFirestore.instance .collection("posts") .doc(widget.eid) .collection("user

我正在尝试使用flutter中的streambuilder生成一个列表,并希望根据firestore时间戳对该列表进行排序。我已经尝试了下面给出的代码

```stream: FirebaseFirestore.instance
                      .collection("posts")
                      .doc(widget.eid)
                      .collection("users")
                      .orderBy("postDate", descending: true)
                      .where("ownerId", isEqualTo: user.userId)
                      .snapshots(),```

我得到的错误是:“查询需要索引。您可以在此处创建它:”我认为你犯了两个错误,首先你使用了ordey by before,这是一种错误的方法,使用where,所以先放在哪里,然后使用order by,然后再使用order by,如果第一个收集字段的空thsts显示为斜体,则不应为空,这样你就无法获取数据。根据firestore,它的手段是由defalut挖掘的。因此,我在查询中进行了更正


stream:firebaseforestore.instnce.collection(“posts”).doc(widget.eid).collection(“users”).where(“ownerid”,isEqualto:user.userId).orderBy(“postdate”,decssending:true).snapshots(),

我已经通过在firestore上添加索引解决了这个问题

谢谢,Muhammad使用firestore中的索引解决了这个问题