其他条件在使用Cloud Firestore的Flutter中不起作用 [英] Else condition not working in Flutter using cloud Firestore
本文介绍了其他条件在使用Cloud Firestore的Flutter中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的如果条件成功运行并且正在检索数据.但是,当数据为null时,我想在Center()中显示文本.尚未添加报价的文本.但是,当数据为null时,它什么也不显示.我尝试了一切.但是执行永远不会达到 else 和 else 条件.有人可以说出我想念的东西吗?
My if condition is successfully working and it is retrieving data. But when data is null, I want to display a text in Center(). Text that no offers are added yet. But it isn't displaying anything when data is null. I tried everything. But execution never goes to else and else if conditions. Can someone shed some light that what am I missing?
child: StreamBuilder(
stream: Firestore.instance.collection('BidList').where('PostID',isEqualTo:args.PostId).snapshots(),
// ignore: missing_return
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if(snapshot.hasData){
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Column(
children: <Widget>[
Container(
// margin: EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Container(
//color: Colors.grey[500],
color: Colors.teal[700],
width: 300,
height: 25,
child: Center(
child: Text(
'Offers List',
style: TextStyle(
fontSize: 18,
fontWeight:
FontWeight.bold,
color: Colors.white),
),
),
)
],
),
),
ListTile(
title: Text(
snapshot.data.documents[index].data['Name']
.toString()
.toUpperCase(),
style: TextStyle(fontSize: 14, color: Colors
.black, fontWeight: FontWeight.bold),
),
leading: CircleAvatar(
//backgroundImage: NetworkImage(w),
// backgroundColor: Colors.blueGrey,
backgroundImage: CachedNetworkImageProvider(data
.toString()),
),
// subtitle: Text(username),
//subtitle: Text(accountCreated.toString()),
subtitle: Row(
children: [
Text('Number: ', style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 10),),
Text(
snapshot.data.documents[index]
.data['Number']
.toString()
.toUpperCase(),
style: TextStyle(
fontSize: 12, color: Colors.black45),
),
],
),
//trailing: Text(timeago.format(timestamp.toDate())),
trailing: Container(
margin: EdgeInsets.all(10),
child: Column(
children: [
Text('Bid', style: TextStyle(
fontWeight: FontWeight.bold),),
Text(
snapshot.data.documents[index].data['Bid']
.toString()
.toUpperCase(),
style: TextStyle(fontSize: 12),),
],
),
),
),
Divider(),
],
),
);
}
);
}
else if(snapshot.hasError || snapshot == null) {
return Container(
child: Column(
children: <Widget>[
Container(
// margin: EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Container(
//color: Colors.grey[500],
color: Colors.teal[700],
width: 300,
height: 25,
child: Center(
child: Text(
'Offers List',
style: TextStyle(
fontSize: 18,
fontWeight:
FontWeight.bold,
color: Colors.white),
),
),
)
],
),
),
Center(child: Text('No Reviews Yet'),),
Divider(),
],
),
);
//
}
else{
return Container(
child: Column(
children: <Widget>[
Container(
// margin: EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Container(
//color: Colors.grey[500],
color: Colors.teal[700],
width: 300,
height: 25,
child: Center(
child: Text(
'Offers List',
style: TextStyle(
fontSize: 18,
fontWeight:
FontWeight.bold,
color: Colors.white),
),
),
)
],
),
),
Center(child: Text('No Reviews Yet'),),
Divider(),
],
),
);
}
},
),
推荐答案
如果您的收藏集中没有文档或数据,则可以添加此条件.
If your collection don't have documents or data your can add this condition.
if(snapshot.hasData){
if (snapshot.data.docs.length != 0) {
return ListView.builder();
} else {
return Text("EMPTY DOCUMENTS");
}
}
这篇关于其他条件在使用Cloud Firestore的Flutter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文