1

I am a complete newbie in programming altogether and this is my first question on this platform. I am writing a medical app in Flutter that works just like Uber using Firebase. I have two apps, (patients and health workers) and both share a single database. On the patient's app, there are icons representing all the medical workers. what I want to do is on the click of a specific icon, I want to fetch the specific 'user_type'(health workers specifically) and display the result on a ListView.

enter image description here

In the 'user-type' I have pharmacists, nurses, doctors, etc.

The code I have written is shown below.

The get function:

  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);
    }
  }

Button code implemented in the scaffold:

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

The Output on the console is:

I/flutter ( 3262): Instance of 'DocumentSnapshot'

If it is not possible, should I change my database structure to focus on different users? For example, a different collection for each medical worker as opposed to them coming under one collection and identified only by the 'user_type" field in the Firestore.

user1506104
  • 6,554
  • 4
  • 71
  • 89
Oscar Ogar
  • 13
  • 5

1 Answers1

1

In your getDoctor() function, you need to change the following

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

to

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

Cheers!

user1506104
  • 6,554
  • 4
  • 71
  • 89
  • Hello, I am trying to use Geofire to query nearby users but I have not been able to. I have studied the docs and implemented every step successfully except the query. It still does not produce the expected results. I can only see myself on the map and not the stored locations of other users. Can you help? – Oscar Ogar Jul 01 '20 at 03:15
  • Please post a new question then link it here. – user1506104 Jul 01 '20 at 04:05
  • https://stackoverflow.com/questions/62668759/getter-error-while-using-geofire-to-query – Oscar Ogar Jul 01 '20 at 04:16