【发布时间】:2019-06-23 09:20:31
【问题描述】:
我一定是把hasData 方法误认为QuerySnaphot。在我的StreamBuilder 中,我想返回一个widget,通知用户collection 中没有任何项目被查询。我已经删除了 Firestore 中的集合,所以那里肯定没有数据。但是当我运行以下代码时:
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('Events')
.where("bandId", isEqualTo: identifier)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
print('code here is being executed 1');// This gets executed
return Text('helllllp');
} else {
print('Code here is being executed2'); //And this gets executed
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Text('Loading...');
default:
return new ListView(
children:
snapshot.data.documents.map((DocumentSnapshot document) {
return CustomCard(
event: document['event'],
location: document['location'],
service: document['service'],
date: document['date'].toDate(),
);
}).toList(),
);
}
}
},
),
我要做的就是返回一个小部件,通知用户快照是否为空。例如Text('You have no messages')
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore