问题描述
StreamBuilder<List<Job>>(
stream: _jobBloc.userJobsObservable,builder: (BuildContext context,AsyncSnapshot<List<Job>> userJobsSnapshot) {
Widget widget;
if (userJobsSnapshot.hasData) {
widget = ListView.builder(
itemCount: userJobsSnapshot.data.length,itemBuilder: (BuildContext context,int index) {
_jobBloc.getJobOffers(userJobsSnapshot.data[index].key);
var totalOffers = 0;
return Column(
children: [
Text(userJobsSnapshot.data[index].someText),StreamBuilder<Map<User,List<Offer>>>(
stream: _offerBloc.getJobOffersObservable,builder: (context,jobOffeRSSnapshot) {
Widget offersWidget;
if (jobOffeRSSnapshot.hasData) {
jobOffeRSSnapshot.data.forEach((key,value) {
totalOffers += value.length;
});
offersWidget = Text(totalOffers > 0
? totalOffers.toString()
: "0 applications");
} else {
offerWidget = Container(
color: Colors.white,child: Center(
child: CircularProgressIndicator(),),);
}
return offerWidget;
}),// close StreamBuilder
]); // close Column
}) // close ListView.builder
} // close if
else {
widget = Container(
color: Colors.white,child: Center(
child: CircularProgressIndicator(),);
}
return widget;
}),// close first StreamBuilder
Job collection - userId (who posted the job)
|-- jobID
|-- job data
User collection - userId
|-- user data
Offer collection - jobId
|-- userId (who posted the offer)
|-- offerId
|-- some data about offer ...
在第一个StreamBuilder中,我打电话来获取作业列表。 然后,我会在文本上打印一些工作信息,然后在下面显示该工作的要约数量以及发布要约的用户个人资料图片(这就是为什么我将“用户”用作地图的键)。因此,我有另一个StreamBuilder,可以为每个用户将报价分组。
然后我进入每个组以添加要约长度列表以获取总数,但是,由于未设置状态,因此文本始终会打印0个应用程序。
如果我尝试setState(),则在构建窗口小部件时收到我尝试设置setState的错误。
如何根据jobOffeRSSnapshot包含的内容显示不同的文本?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)