gpt4 book ai didi

flutter - 条件为 "met"(!snapshot.hasData) 后未返回小部件

转载 作者:IT王子 更新时间:2023-10-29 07:02:50 25 4
gpt4 key购买 nike

我有一个标准的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(),

最佳答案

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

关于flutter - 条件为 "met"(!snapshot.hasData) 后未返回小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56680829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com