从火力地堡获取数据

时间:2018-09-04 00:37:58

标签: firebase flutter google-cloud-firestore

我需要从firebase中获取特定元素。我不需要流生成器,只需要一个元素。谁能帮我 ?

我有这个:

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

1 个答案:

答案 0 :(得分:0)

也许这可以帮助您

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