【问题标题】:Querying a specific value from a field that has more than one value in flutter from firestore从firestore中查询具有多个值的字段中的特定值
【发布时间】:2020-10-08 01:36:55
【问题描述】:

我完全是一个编程新手,这是我在这个平台上的第一个问题。我正在用 Flutter 编写一个医疗应用程序,就像使用 Firebase 的 Uber 一样。我有两个应用程序(患者和卫生工作者)并且都共享一个数据库。在患者的应用程序上,有代表所有医务人员的图标。我想要做的是点击一个特定的图标,我想获取特定的'user_type'(特别是卫生工作者)并在 ListView 上显示结果。

在“用户类型”中,我有药剂师、护士、医生等。

我写的代码如下所示。

get函数:

  void getDoctors() async {
    try {
      final doctors = await _firestore
          .collection('users')
          .where('user_type', isEqualTo: 'doctor')
          .getDocuments();
      for (var doctor in doctors.documents) {
        print(doctor);
      }
    } catch (e) {
      print(e);
    }
  }

脚手架中实现的按钮代码:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: RaisedButton(
          child: Text(
            'search',
            style: kSendButtonTextStyle,
          ),
          onPressed: () {
            getDoctors();
          },
        ),
      ),
    );

控制台上的输出是:

I/flutter (3262):“DocumentSnapshot”的实例

如果不可能,我应该改变我的数据库结构以关注不同的用户吗?例如,每个医务人员的不同集合,而不是属于一个集合并仅由 Firestore 中的“user_type”字段标识。

【问题讨论】:

    标签: android flutter google-cloud-firestore


    【解决方案1】:

    在您的 getDoctor() 函数中,您需要更改以下内容

    for (var doctor in doctors.documents) {
        print(doctor);
    }
    

    for (var doctor in doctors.documents) {
        print(doctor.data);
    }
    

    干杯!

    【讨论】:

    • 您好,我正在尝试使用 Geofire 来查询附近的用户,但我无法做到。除了查询之外,我已经研究了文档并成功实施了每一步。它仍然没有产生预期的结果。我只能在地图上看到自己,而不是其他用户的存储位置。你能帮忙吗?
    • 请发布一个新问题,然后在此处链接。
    猜你喜欢
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-28
    • 2020-01-04
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多