【问题标题】:I want .orderBy('Name', descending: false) close no problem but open it error我想要 .orderBy('Name', descending: false) 关闭没问题但打开它出错
【发布时间】:2021-06-04 05:59:28
【问题描述】:

我要 .orderBy('Name', descending: false) 关闭没问题但打开出错。

StreamBuilder<QuerySnapshot>(
    stream: (name != '' && name != null)
        ? FirebaseFirestore.instance
            .collection('BeeBox')
            .where("Idfarm", isEqualTo: widget.idFram)
            .where("Name", isEqualTo: name)
            .snapshots()
        : FirebaseFirestore.instance
            .collection("BeeBox")
            .where("Idfarm", isEqualTo: widget.idFram)
            .orderBy('Name', descending: false)
            .snapshots(),
    builder: (context, snapshot) {
      return (snapshot.connectionState == ConnectionState.waiting)
          ? Center(child: CircularProgressIndicator())
          : ListView.builder(
              itemCount: snapshot.data.docs.length,
              itemBuilder: (context, index) {
                DocumentSnapshot data = snapshot.data.docs[index];
                return Container(child: ListTile(
            title: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  // beeboxModels[index].name ?? 'กำลังโหลด',
                  data['Name'],
                  style: GoogleFonts.sarabun(
                    textStyle: TextStyle(
                        color: Colors.black,
                        fontWeight: FontWeight.bold),
                    fontSize: 20,
                  ),
                ),
              ],
            ),
            subtitle: Text(
              // beeboxModels[index].location ?? 'กำลังโหลด',
              data['LocationName'],
              style: GoogleFonts.sarabun(
                textStyle: TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.bold),
                fontSize: 13,
              ),
            ),
            dense: true,
          ),);
               },
            );
    },
  ),

终端:

W/Firestore(29683):整数值:0

W/Firestore(29683): string_value: "W4i9SnmR7lyoL0fc33TB" order by Name, name);limitType=LIMIT_TO_FIRST) failed: Status{code=FAILED_PRECONDITION, description=查询需要索引。你可以在这里创建它:https://console.firebase.google.com/v1/r/project/bee-app-65be5/firestore/indexes?create_composite=Ckxwcm9qZWN0cy9iZWUtYXBwLTY1YmU1L2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9CZWVCb3gvaW5kZXhlcy9fEAEaCgoGSWRmYXJtEAEaCAoETmFtZRABGgwKCF9fbmFtZV9fEAE,cause=null}
I/flutter (29683):引发了另一个异常:NoSuchMethodError:在 null 上调用了 getter 'docs'。 I/FirebaseAuth(29683): [FirebaseAuth:] 准备创建服务连接到后备实现 W/System (29683):忽略标头 X-Firebase-Locale,因为它的值为 null。

【问题讨论】:

    标签: flutter dart google-cloud-firestore


    【解决方案1】:

    正如错误消息所述:您尝试执行的查询要求您显式为其创建复合索引。如果您单击错误消息中的 URL,它将带您进入 Firebase 控制台,其中预先填充了所有值以创建该索引。

    【讨论】:

    • 非常感谢您的帮助。
    猜你喜欢
    • 2020-07-24
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2017-08-08
    • 2011-06-30
    • 2015-07-21
    • 2022-06-16
    相关资源
    最近更新 更多