firebase - Flutter Cloud Firestore isLessThan 过滤器不使用两个 .where() 语句
问题描述
我正在使用StreamBuilder
. 目前,我可以使用.where()
语句按标题(字符串)过滤此文档列表,但我想添加另一个.where()
语句按价格(数字)过滤。我希望该应用程序仅显示标题等于某个字符串且价格小于某个数字的文档列表。按标题过滤可以正常工作,但问题在于isLessThan
添加第二条.where()
语句时的操作员。
当前代码(一条.where()
语句):
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection("ads")
.where('title', isEqualTo: "Car")
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text(
"Loading...");
} else {
return //Rest of the code isn't relevant
}
},
),
我想使用两个.where()
语句的代码(它只返回加载文本,这意味着快照没有任何数据):
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection("ads")
.where('title', isEqualTo: "Car")
.where('price', isLessThan: 12000.0) //This line is new
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text(
"Loading...");
} else {
return //Rest of the code isn't relevant
}
},
),
我无法确定这是否是存在两个.where()
语句的问题,或者是否是isLessThan
操作员的问题。删除第一个声明(关于标题的声明)并保留第二个关于价格的声明,按价格正确过滤文档(理论上使问题成为有 2 个声明.where()
的事实)。.where()
但是,将第二isLessThan
个.where()
语句中的 这让我认为将运算符和第二条语句结合起来是一个问题。isEqualTo
12000.0
.where()
isLessThan
.where()
注意:Firestore 集合中的所有价格值都是双精度值(Cloud Firestore 中的数据类型设置为“数字”并且它们都有小数 - 例如 1.0 而不是 1)。
解决方案
推荐阅读
- node.js - 从节点js中的远程流读取时写入远程流
- c# - 从需要 VPN 的 azure 访问站点
- linux - 如何配置命令以在 AWS ec2 实例 cpu 利用率超过一定百分比时自动执行
- android - 版本代码 1 已被使用。尝试其他版本代码
- pine-script - 为什么我的标签文本一直重复而不是每行一次
- python - 如何引入不在每一行中的新列?
- elementor - 我可以从 Elementor 中的视频播放列表生成的 URL 中删除参数吗
- postgresql - 如何将 postgresql 与 Xamarin 连接?
- swift - AlertController 视图不在窗口层次结构中
- c++ - 除非给出诊断、优化器或标准标志,否则 g++ 会忽略内联关键字 (odr)?