在flutter中检索某些Firebase文档的集合

时间:2020-05-04 12:37:49

标签: firebase flutter google-cloud-firestore

文档名称是auth用户,但我无法将其检索为Firestore中的索引,我只需要指向user.uid并检索其集合

StreamBuilder(
          stream: Firestore.instance.collection("Attendees").snapshots(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.hasData) {
              return new ListView.builder(
                  shrinkWrap: true,
                  itemCount: snapshot.data.documents.length,
                  padding: const EdgeInsets.only(top: 5.0),
                  itemBuilder: (context, index) {
                    DocumentSnapshot ds = snapshot.data.documents[index];
                    return new Row( 
                      textDirection: TextDirection.ltr,
                      children: <Widget>[
                        Expanded(child: Text(ds['absenceDay'])),
                        Expanded(child: Text(ds['excuse'])),
                      ],
                    );
                  });
            }
          },
        )

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试以下操作:

  getDocument() async {
    FirebaseUser user = await FirebaseAuth.instance.currentUser();
     return Firestore.instance.collection("Attendees").document(user.uid).snapshots();
  }

然后在StreamBuilder中使用它:

StreamBuilder(
 stream: getDocument(),
 builder: (BuildContext context, AsyncSnapshot snapshot) {
 if (snapshot.hasData) {