【发布时间】: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