如何仅从具有子集合的文档中获取documentId

时间:2020-05-03 10:01:56

标签: firebase flutter google-cloud-firestore

我的目标是获取带有Date的标头,该标头是documentId。之后,我想从该文档的子集合中获取所有不同的文档。但这并不超出print('test3'); ArchivedStream适用于所有其他文档,是一个额外的Class,需要在Date小部件下构建其小部件。 有人可以帮忙吗...

 class GetDates extends StatelessWidget {


  GetDates({this.referenceforarchived});
  final String referenceforarchived;


  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _fetchdata,
      builder: (context, myFuture) {
        if (myFuture.connectionState == ConnectionState.done &&
            !myFuture.hasError) {
          return StreamBuilder<QuerySnapshot>(
            stream: _firestore
                .collection('users')
                .document(loggedinUser.uid)
                .collection('Dates')
                .snapshots(),
            builder: (context, snapshot) {
              if (!snapshot.hasData ||
                  snapshot.hasError ||
                  snapshot.data == null ||
                  snapshot.connectionState == ConnectionState.waiting ||
                  loggedinUser.email == null) {
                return (Center(child: CupertinoActivityIndicator()));
              }
              print('test');
              final items = snapshot.data.documents.reversed;
              print('test2');
              List<DatesItems> dates = [];
              print('test3');
              for (var date in items) {
                print('test3');
                final dateid = date.documentID;
                final datem = date.data; 
                print(dateid);
                print(datem);


                final datesItems = DatesItems(
                  text: dateid,
                  documentReference: date.reference,
                );

                dates.add(datesItems);
                // ArchivedStream(
                //   reference: date.reference,
                //   referenceforarchived: referenceforarchived,
                // );
              }

              return Column(
                children: dates,
              );
            },
          );
        } else {
          return CupertinoActivityIndicator();
        }
      },

    );
  }
}

好的,所以我在Firebase中使用了一个测试项目来尝试它,并且可行!我究竟做错了什么?日期项与文档ID一起保存为动态文件,但由于某种原因无法访问...

enter image description here

0 个答案:

没有答案