如何访问嵌套集合结构中最里面的文档?

时间:2020-09-04 06:29:59

标签: flutter

如图所示,firestore中有一个收集结构。我想通过到达最后的文档信息以列表视图显示它。但是我无法在屏幕上查看它。

enter image description here

代码在这里:

     @override
  Widget build(BuildContext context) {

      randevular = databaseRef
          .collection(
          'kuaforumDB/$_salonID/BekleyenRandevular/')
          .snapshots();

    return StreamBuilder<QuerySnapshot>(
        stream: randevular,
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if(!snapshot.hasData) {
            return Column(

              children:<Widget> [
                SizedBox(
                  height: 100,
                ),
                Center(
                  child: Image.asset("assets/images/icons/fon.webp",matchTextDirection: true,
                    height: 140.0,
                    width: 140.0,
                  ),),
                SizedBox(
                    height: 20
                ),
                Center(
                    child: new Text('Henüz bir randevu oluşturmadınız.')
                )

              ],


            );
          }
          else if (snapshot.connectionState == ConnectionState.waiting) {
            return Center(
                child: new Center(
                  child: new CircularProgressIndicator(
                    value: null,
                    strokeWidth: 7.0,
                  ),
                )
            );
          } else {

            return ListView(
              children: snapshot.data.documents
                  .map((document) {
                    var query = databaseRef
                        .collection('kuaforumDB/')
                        .document('$_salonID')
                        .collection('BekleyenRandevular')
                        .document(document.documentID)
                        .collection('get')
                        .snapshots();
                 return StreamBuilder<QuerySnapshot> (
                                stream: query,
                      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot2){
                        if (!snapshot2.hasData) return Text("Loading...");
                       return ListView(
                          children: snapshot2.data.documents
                              .map((DocumentSnapshot doc) => Card(
                              child:  ListTile(
                                leading: IconButton(
                                  tooltip: '',
                                  icon: const Icon(Icons.check_circle, color: Colors.red,),
                                  color: doc['randevuTarih']
                                      .toDate()
                                      .isBefore(DateTime.now())
                                      ? Colors.green
                                      : Colors.orangeAccent,
                                  iconSize: 30,
                                  onPressed: () {},
                                ),
                                title: Text(AppConstants.formatter
                                    .format((doc['randevuTarih'].toDate())
                                    .add(Duration(hours: 0)))
                                    .toString()),
                                subtitle: Text('Randevu Onay Bekleniyor.'),
                                trailing: Icon(Icons.keyboard_arrow_right,
                                    color: Colors.grey, size: 30.0),
                                onTap: () {
                                  Navigator.push(
                                      context,
                                      MaterialPageRoute(
                                          builder: (content) => MyPendingDetailPage(
                                            salonID: _salonID.toString(),
                                            userID: mPhone,
                                            randevuID:
                                            doc.documentID.toString(),
                                            randevuTarih: AppConstants
                                                .formatter
                                                .format((doc['randevuTarih']
                                                .toDate())
                                                .add(Duration(hours: 0)))
                                                .toString(),
                                            randevuHizmet: doc['hizmetler'],
                                            randevuFiyat:
                                            doc['fiyat'].toString(),
                                            randevuSure:
                                            doc['sure'].toString(),
                                            randevuFavori:
                                            doc['favori'] == null
                                                ? false
                                                : doc['favori'],
                                            randevuBittimi:
                                            doc['randevuTarih']
                                                .toDate()
                                                .isBefore(
                                                DateTime.now())
                                                ? true
                                                : false,
                                            ayBasi: startofmonth,
                                            sonrandevu : doc['randevuTarih'],
                                          )));
                                }, )))
                              .toList(),
                        );
                      },
                    );
            }).toList());
          }
        });
  }

在上面的代码中使用嵌套的Listview可能引起了一个问题。但是我不知道该怎么解决。当我检查它时,我看到我实际上可以拉出数据,但是我无法在屏幕上显示它。

enter image description here

0 个答案:

没有答案