条件为“ met”后未返回窗口小部件(!snapshot.hasData)

时间:2019-06-20 07:14:55

标签: flutter dart

我有一个标准的StreamBuilder。从Firestore返回列表的效果很好,但是我想在查询为空时返回小部件。为此,我使用条件(!snapshot.hasData)。但是当收藏集为空时,我得到的只是一个空白屏幕。我想退回Text Widget您好:

StreamBuilder<QuerySnapshot>(
            stream: Firestore.instance
                .collection('Events')
                .where("bandId", isEqualTo: identifier)
                .snapshots(),
            builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
              if (!snapshot.hasData)
                return Center(
                    child: Text(
                  'hello',
                  style: TextStyle(color: Colors.black),
                ));
              switch (snapshot.connectionState) {
                case ConnectionState.waiting:
                  return new Text('Loading...');
                default:
                  return new ListView(
                    children:
                        snapshot.data.documents.map((DocumentSnapshot document) {
                      return Dismissible(
                        key: new Key(document.documentID),
                        onDismissed: (direction) {
                          Firestore.instance.runTransaction((transaction) async {
                            DocumentSnapshot snapshot =
                                await transaction.get(document.reference);
                            await transaction.delete(snapshot.reference);
                          });
                          Fluttertoast.showToast(msg: "Event Deleted");
                        },
                        child: CustomCard(
                          event: document['event'],
                          location: document['location'],
                          service: document['service'],
                          date: document['date'].toDate(),
                        ),
                      );
                    }).toList(),

1 个答案:

答案 0 :(得分:0)

请尝试在“ if(!snapshot.hasData)”上设置断点,以查看接收到的内容以及应用程序的运行方向(此后执行了哪些行),if条件之后也没有{}括号。