我有一个标准的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(),
答案 0 :(得分:0)
请尝试在“ if(!snapshot.hasData)”上设置断点,以查看接收到的内容以及应用程序的运行方向(此后执行了哪些行),if条件之后也没有{}括号。