当我在我的 flutter 应用程序中使用 cloud firestore 时,发生了奇怪的异常。
已编辑
这是我的代码:
Stream<List<Product>> productsStream(int id) async* {
final k = _db
.collection('products')
.where('category_id', isEqualTo: id)
.where('stock', isGreaterThanOrEqualTo: 1)
.orderBy('order')
.snapshots();
yield* k.map((event) => event.docs
.map((e) => Product.fromJson(
e.data(),
))
.toList());
Run Code Online (Sandbox Code Playgroud)
在这里,我想要实现的是检查产品是否有库存,然后order在我的products收藏中按字段升序订购产品。
但我收到这个奇怪的错误:
例外:'package:cloud_firestore/src/query.dart':断言失败:第 421 行 pos 16:'field == orders[0][0]':初始 orderBy() 字段 '[[FieldPath([order]) , false]][0][0]' 必须与调用不等式运算符时的 where() 字段参数 'FieldPath([stock])' 相同。
什么可能是解决方案?