初始 orderBy() 字段"[[FieldPath([id]), true]][0][0]"必须与 where() 字段参数相同



在执行Orderby和Query Together时发生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,
),
);
}

运行代码时出错

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]'

初始orderBy((字段"[[FieldPath([id](,true]][0][0]";必须与where((字段参数"相同;FieldPath([price](";什么时候调用不等式运算符。

这意味着第一个orderBy必须是对其执行不等式查询的字段,即price

  • 从以下位置更新您的查询:
query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('id',descending: true)

至:

query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('price').orderBy('id',descending: true)
  • 运行此查询,您将在控制台上收到一条消息和一个链接,其中表示您需要创建一个索引。

  • 单击链接并创建索引。

  • 等待索引完成创建过程,然后再次运行查询。

最新更新