Noo*_*per 6 flutter google-cloud-firestore
同时执行 Orderby 和 Query 时 Firestore 出现错误
我不知道它是包还是查询。什么时候
body: PaginateFirestore(
itemBuilderType: PaginateBuilderType.listView,
itemBuilder: (index, context, documentSnapshot) {
final data = documentSnapshot.data() as Map?;
// final sub = data.
return InkWell(
onTap: () {},
child: ListTile(
leading: CircleAvatar(child: Icon(Icons.person)),
title: data == null ? Text('Error in data') : Text(data['id']),
),
);
},
// orderBy is compulsory to enable pagination
query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('id',descending: true),
// to fetch real-time data
isLive: true,
),
);
}
Run Code Online (Sandbox Code Playgroud)
运行代码时出错
The following assertion was thrown building Retrive(dirty):
The initial orderBy() field "[[FieldPath([id]), true]][0][0]" has to be the same as the where() field parameter "FieldPath([price])" when an inequality operator is invoked.
'package:cloud_firestore/src/query.dart':
Failed assertion: line 484 pos 13: 'conditionField == orders[0][0]'
Run Code Online (Sandbox Code Playgroud)
Vic*_*ele 12
当使用不等运算符时,初始 orderBy() 字段“[[FieldPath([id]), true]][0][0]”必须与 where() 字段参数“FieldPath([price])”相同被调用。
这意味着第一个orderBy必须是您执行不等式查询的字段,即price。
query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('id',descending: true)
Run Code Online (Sandbox Code Playgroud)
到:
query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('price').orderBy('id',descending: true)
Run Code Online (Sandbox Code Playgroud)
运行此查询,您将在控制台上收到一条消息以及一个链接,表明您需要创建一个索引。
单击链接并创建索引。
等待索引完成创建过程并再次运行查询。
| 归档时间: |
|
| 查看次数: |
2979 次 |
| 最近记录: |