getter'documents'在null上被调用。接收方:空尝试调用:文档

时间:2020-11-01 21:18:04

标签: flutter dart google-cloud-firestore

我遇到了一个奇怪的问题,有声读物中有很多文档,但是当我尝试使用Streambuilder调用它时,没有任何显示。

错误信息:

以下NoSuchMethodError被抛出 StreamBuilder(脏,状态:_StreamBuilderBase State #98258):获取器 “文档”在null上被调用。接收方:null尝试调用: 文件

注意:当我将有声读物替换为培训课程时,该应用程序将运行并获取培训课程中的元素>。 有声读物中的元素与培训课程中的元素相似。

StreamBuilder(
                        stream: Firestore.instance
                            .collection("Sections")
                            .document("Audiobooks")
                            .collection("All")
                            .orderBy("dateAdded", descending: true)
                            .snapshots(),
                        builder: (context, snapshot) {
                          if (!snapshot.hasData) {
                            return Container(
                              height: 0,
                              width: 0,
                            );
                          }

                          else if(snapshot.hasError)
                          {
                            return Container(
                              height: 0,
                              width: 0,
                            );
                          }

                            else if(snapshot.data == null) return CircularProgressIndicator();

                          else {
                            return GridView.count(
                              shrinkWrap: true,
                              crossAxisCount: 2,
                              primary: true,
                              padding: const EdgeInsets.all(5.0),
                              physics: NeverScrollableScrollPhysics(),
                              scrollDirection: Axis.vertical,

                              children: List.generate(snapshot.data.documents.length, (index) {
                                DocumentSnapshot item =
                                snapshot.data.documents[index];

                                return Card(
                                  child: Column(
                                    // mainAxisSize: MainAxisSize.max,
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: <Widget>[
                                      Expanded(
                                        child: Stack(
                                          fit: StackFit.expand,
                                          children: <Widget>[
                                            Container(
                                              height: MediaQuery.of(context).size.height,
                                              width: MediaQuery.of(context).size.height,
                                              decoration: BoxDecoration(
                                                image: DecorationImage(
                                                    image: CachedNetworkImageProvider(
                                                      item["img"],
                                                    ),
                                                    fit: BoxFit.cover),
                                                borderRadius: BorderRadius.only(topRight:  Radius.circular(5), topLeft: Radius.circular(5)),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                      Padding(
                                        padding: EdgeInsets.all(10.0),
                                        child: Column(
                                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                                          children: <Widget>[
                                            Text(
                                              item["nameAR"],
                                              textAlign: TextAlign.center,
                                              style: TextStyle(
                                                fontSize: 16.0,
                                                color: GlobalUniversal.blackColor,
                                                fontWeight: FontWeight.bold,
                                                fontFamily: widget.availableEN == true ? widget.myAppLang != "en" ? FONT_AR : FONT_EN : FONT_AR,),
                                            ),
                                            Text(
                                              widget.availableEN == true ?  widget.myAppLang != "en" ? "${DURATION_AR}: ${item[DURATION_DB]}" : "${DURATION_EN}: ${item[DURATION_DB]}" : "${DURATION_AR}: ${item[DURATION_DB]}",
                                              style: TextStyle(color: Colors.grey[500]),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                );
                              }),
                            );
                          }


                        },
                      ),

有声读物路径 enter image description here

enter image description here

培训课程路径 enter image description here

enter image description here

0 个答案:

没有答案