Eduardo Vasconcelos
Eduardo Vasconcelos

Reputation: 15

Display document with variable true - Flutter Firebase

I have to show on the screen only the users that the ACTIVE variable is true. However I am not able to achieve this condition, it always displays all users registered in Firebase. How to do this for this code in question?

Expanded(
            child: StreamBuilder<QuerySnapshot>(
              stream: getListaPacientes(),
              builder: (context, snapshot){
                switch(snapshot.connectionState){
                  case ConnectionState.none:
                  case ConnectionState.waiting:
                  return Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                              Icon(Icons.error_outline),
                              Text("Usuário não encontrado")                                                
                      ],
                    ),
                  );
                  default:
                    List<DocumentSnapshot> documentos =
                      snapshot.data.documents;
                    return ListView.builder(
                      itemCount: documentos.length,
                      itemBuilder: (context, index){
                        return ListTile(
                          title: Text(items[index].nome,
                            style: TextStyle(fontSize: 16)),
                          subtitle: Text('Quarto: ${items[index].quarto}',
                            style: TextStyle(fontSize: 16)),
                          leading: CircleAvatar(
                            backgroundImage: NetworkImage(items[index].foto),
                          ),
                                onTap: ()=> _navegarParaPerfil(context, items[index]),
                        );
                      }
                      );
                }
              }
            ),
            )
 Stream<QuerySnapshot> getListaPacientes(){
    return Firestore.instance.collection('pacientes').snapshots();
  }

What do you suggest to fix this imperfection? Thank you very much!

Upvotes: 0

Views: 244

Answers (1)

Balasubramani Sundaram
Balasubramani Sundaram

Reputation: 1290

you can use the where API to retrieve the ACTIVE users from the firebase.

  final CollectionReference collection =
      FirebaseFirestore.instance.collection('employees');

  Stream<QuerySnapshot> getStream() {
    return collection.where('ACTIVE', isEqualTo: true).snapshots();
  }

Upvotes: 1

Related Questions