【问题标题】:Why does flutter streambuilder query using 'orderby' cause an error为什么flutter streambuilder查询使用'orderby'会导致错误
【发布时间】:2021-10-30 07:01:05
【问题描述】:

为什么我的StreamBuilder 返回出了问题?这个流工作得很好,但是当添加orderBy 时,它说出了点问题。 Database

Padding(
                      padding: const EdgeInsets.only(
                        left: 20,
                      ),
                      child: StreamBuilder<QuerySnapshot>(
                        stream: FirebaseFirestore.instance
                            .collection("notifications")
                            .where("parentUID",
                                isEqualTo:
                                    FirebaseAuth.instance.currentUser!.uid)
                            .orderBy('timestamp')
                            .snapshots(),
                        builder: (BuildContext context,
                            AsyncSnapshot<QuerySnapshot> snapshot) {
                          if (snapshot.hasError) {
                            return Text('Something went wrong');
                          }

                          if (snapshot.connectionState ==
                              ConnectionState.waiting) {
                            return Text("Loading");
                          }
                          return Column(
                            children: snapshot.data!.docs.map(
                              (DocumentSnapshot document) {
                                Map<String, dynamic> data =
                                    document.data()! as Map<String, dynamic>;
                                return adminNotifCard(
                                  text1: data['notifTitle'],
                                  text2: data['notifNotes'],
                                );
                              },
                            ).toList(),
                          );
                        },
                      ),
                    ),

Error

【问题讨论】:

  • 接下来,如果snapshot.hasError 返回true,您将需要记录来自snapshot.error 的实际错误。这将准确地告诉你出了什么问题。

标签: android firebase flutter google-cloud-firestore


【解决方案1】:

我通过转到 Cloud Firestore 中的索引选项卡解决了这个问题

然后选择通知集合并使其上升,一开始它不起作用,但在说building之后,它说启用并且我热重启。成功了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 2020-07-16
    • 2014-06-05
    • 1970-01-01
    相关资源
    最近更新 更多