I'm creating todo list in which I'll have two lists one for incomplete tasks and another for completed tasks...I'm able to retrieve the data from Firestore by pulling the whole data without any condition, but for the uncompleted list, I want to retrieve the document only with particular field values. For example, each document contains the following fields as shown in the picture:enter image description here

下面是我用来从Firebase FireStore获取数据的代码:

static List<Task> getTasks() {
    //convert firebase collection to list
    List<Task> tasks = [];
    FirebaseFirestore.instance.collection('Todos').snapshots().listen((data) {
      data.docs.forEach((doc) {
        tasks.add(Task.fromMap(doc.data()));
      });
    });
    return tasks;
  }

我希望类似这样的函数只检索taskStatus==True的文档.因此,我可以将taskStatus为True的所有任务存储在单独的列表中,并相应地显示它们.

推荐答案

您可以使用where功能.它的工作原理如下. 更多信息:Cloud FireStore Filtering

FirebaseFirestore.instance
  .collection('Todos')
  .where('taskStatus', isEqualTo: true)
  .snapshots().listen((data) {
    data.docs.forEach((doc) {
      other_tasks.add(Task.fromMap(doc.data()));
    });
  });

Flutter相关问答推荐

如何使用新的Riverpod语法将依赖传递给AsyncNotifier?

使用自定义控制器将项插入到ListView中时行为不正确

如何将 colored颜色 阴影作为默认容器 colored颜色 应用于自定义窗口小工具?

你能go 掉Flutter 小部件测试中的样板吗?

BoxConstraints强制使用无限宽度(列中的Listview)

在Flutter 小部件测试中找不到框中的AssetImage装饰

在Ffltter中,我已经使用了Ffltter_BLOC Cupit和Pusher,但当获得新数据时,UI没有更新

Flutter GestureDetector单击问题-堆叠外面的按钮不可点击

导航回上一页会将我带回Ffltter应用程序中的登录页面

顶部对齐ListTile的[前导、标题、尾随]小部件

我如何在Android 13中通过Flutter应用程序打开文件(不是图像、视频或音频)?

在带有 flutter 的 Native Android 中,EventChannel.EventSink 始终为 null

尽管我的 url 链接正确,但 ArgumentError(无效参数:URI 文件中未指定主机:///)错误

如何在flutter中将所有单词的第一个字母大写

在 Flutter 中使用条件语句设置 ImageProvider Object 类型的背景图像

Flutter 自定义对齐

Flutter - 我需要显示文本,但应用程序不需要

如何使用 Riverpod 在运行时动态创建提供程序?

根据索引/变量更改小部件的 colored颜色

Flutter Desktop,如何获取windows用户配置文件名称?