【问题标题】:Retrieve collection of certain firebase document in flutter在颤动中检索某些firebase文档的集合
【发布时间】:2020-05-04 12:37:49
【问题描述】:

文档名称是 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'])),
                      ],
                    );
                  });
            }
          },
        )

【问题讨论】:

  • 有什么问题?在您的代码中,您正在检索集合中的内容,您到底是什么?
  • 我希望索引只指向 1 个集合 此代码检索里面的所有文档我只需要检索 1 个包含 uid 名称的文档

标签: firebase flutter google-cloud-firestore


【解决方案1】:

尝试以下方法:

  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) {

【讨论】:

猜你喜欢
  • 2020-08-04
  • 2021-11-11
  • 1970-01-01
  • 2021-03-24
  • 2023-04-04
  • 2020-01-05
  • 1970-01-01
  • 1970-01-01
  • 2021-03-17
相关资源
最近更新 更多