0
votes

im getting a list of objects from my cloud firestore database but even when my collection is empty or not even exist my streamBuilder keep going inside (snapshot.hasData == true)

StreamBuilder<List<Patient>>(
        stream: FirebaseApi().getAllPatients,
        builder: (context, snapshot) {
          if (snapshot.hasData == true) {
            var data = snapshot.data;
            return Column(
              children: [
                buildSearch(),
                query == ''
                    ? buildAllPatients(data)
                    : filteredPatientsNum(data: data).length != 0
                        ? buildFilteredPatients(data)
                        : Center(
                            child: Text('No Patients Found'),
                          ),
              ],
            );
          } else if (snapshot.hasData == false) {
            return Center(child: Text('No Patients'));
          }
          return Center(child: CircularProgressIndicator());
        },
      ),

the result on the emulator here

what i want to do is to enter the case (snapshot.hasdata == false) and show the text ('no patients') on the screen when my collection has no documents or not existed

here is the stream code

  Stream<List<Patient>> get getAllPatients {
    return FirebaseFirestore.instance
        .collection('Patients')
        .snapshots()
        .map(patientsListFromQuerySnapShot);
  }