Bryansq2nt
Bryansq2nt

Reputation: 394

Get data from firebase to flutter

I need to get a specific element from firebase. I do not need a stream builder, I only need one element. Can anyone help me ?

I have this :

final DocumentReference postRef = Firestore.instance.collection('Usuarios').document(email);

Firestore.instance.runTransaction((Transaction tx) async {
    DocumentSnapshot postSnapshot = await tx.get(postRef);
    if(postSnapshot.exists)
    {
        // do something
    }
}

Upvotes: 1

Views: 224

Answers (1)

Gabriel Cortes
Gabriel Cortes

Reputation: 120

maybe this can help you

    QuerySnapshot querySnapshot = await Firestore.instance
                    .collection('Usuarios')
                    .where("email", isEqualTo: email)
                    .getDocuments();

     var userList = querySnapshot.documents; 
     List<DocumentSnapshot> ds = userList;

     ds.forEach((u) {
       userName = u.data["name"];
     });

Upvotes: 1

Related Questions