Bad state: Stream has already been listened to.
https://stackoverflow.com/questions/51396769/flutter-bad-state-stream-has-already-been-listened-to
The most common form of Stream can be listened only once at a time. If you try to add multiple listeners, it will throw
Bad state: Stream has already been listened to
To prevent this error, expose a broadcast Stream. You can convert your stream to a broadcast using myStream.asBroadcastStream
This needs to be done inside your class that expose Stream. Not as parameter of StreamBuilder. Since asBroadcastStream internally listen to the original stream to generate the broadcast one, this imply you can't call this method twice on the same stream.
Thank you Rémi Rousselet for your response. I exposed the broadcast stream by simply calling myStream.asBroadcastStream. But i am getting snapshot.hasData as null and the progressbar keeps moving as the streambuilder might not able to fetch the data. – Mercy peka J
I have had the same issue when I used a result of Observable.combineLatest2 for StreamBuilder into Drawer:
flutter: Bad state: Stream has already been listened to.
As for me, the best solution has added the result of this combine to new BehaviorSubject and listen new one.
Don't forget to listen old one !!!
class VisitsBlocc extends Object {I didn't use
Map<Visit, Location> visitAndLocation; VisitsBloc() {
visitAndLocations.listen((data) {
visitAndLocation = data;
});
} final _newOne = new BehaviorSubject<Map<Visit, Location>>(); Stream<Map<Visit, Location>> get visitAndLocations => Observable.combineLatest2(_visits.stream, _locations.stream, (List<vis.Visit> visits, Map<int, Location> locations) {
Map<vis.Visit, Location> result = {}; visits.forEach((visit) {
if (locations.containsKey(visit.skuLocationId)) {
result[visit] = locations[visit.skuLocationId];
}
}); if (result.isNotEmpty) {
_newOne.add(result);
}
});
}.broadcastbecause it slowed my UI.
Bad state: Stream has already been listened to.的更多相关文章
- node中的Stream-Readable和Writeable解读
在node中,只要涉及到文件IO的场景一般都会涉及到一个类-Stream.Stream是对IO设备的抽象表示,其在JAVA中也有涉及,主要体现在四个类-InputStream.Reader.Outpu ...
- Stream探究
http://segmentfault.com/a/1190000003479884 1. 认识Stream Stream的概念最早来源于Unix系统,其可以将一个大型系统拆分成一些小的组件,然后将这 ...
- Java Stream 使用详解
Stream是 Java 8新增加的类,用来补充集合类. Stream代表数据流,流中的数据元素的数量可能是有限的,也可能是无限的. Stream和其它集合类的区别在于:其它集合类主要关注与有限数量的 ...
- 简单了解node stream
Almost all Node.js applications, no matter how simple, use streams in some manner. 开篇先吓吓自己.画画图,分析分析代 ...
- 谈谈stream的运行原理
害,别误会,我这里说的stream不是流式编程,不是大数据处理框架.我这里说的是stream指的是jdk中的一个开发工具包stream. 该工具包在jdk8中出现,可以说已经是冷饭了,为何还要你说?只 ...
- C# 实现 微软WebRequestMethods.Ftp类中的FTP操作功能
先奉献一个测试地址,ftp内的文件请勿删除,谢谢 FtpEntity fe = "); 由于代码量较多,只抽出一部分,详细代码请移步 ftp://wjshan0808.3vhost.net ...
- Trident中的DRPC实现
一:介绍 1.说明 Storm里面引入DRPC主要是利用storm的实时计算能力来并行化CPU intensive的计算.DRPC的storm topology以函数的参数流作为输入,而把这些函数调用 ...
- Trident中使用HBase进行状态管理
1.使用的类 2.使用HBaseMapState 3.使用状态管理 使用的状态管理还要看Spout StateFactory factory1 = HBaseMapState.opaque(opts1 ...
- Trident继承kafka
1.Kafka涉及的类 上一个类是不透明事务 后一个是完全事务 2.启动服务 3..驱动类 重要的地方是修改了两个部分: 1.数据的来源是kafka 2.第二个是字段的Fields是str packa ...
随机推荐
- 通过Zabbix监控Tomcat单机多实例
前面已经介绍过Tomcat单机多实例部署,接下来就在他的基础上进行下一步操作:Tomcat多实例监控! Tomcat多实例监控过程和之前的redis多实例原理一样,分为以下4步: 1.获取多实例 2. ...
- LOL佐伊官方手办
花199元在某宝上买的官方正版佐伊手办终于到了,话不多说直接上图! 虽然脸有点不切实际的大,但还是很可爱~
- 怎么对ORACLE里的CLOB字段进行模糊查询
select b.* from oss_service_log a left join oss_service_log_detail b on a.pk_log = b.pk_log where a. ...
- python 玩爬虫安装了一大堆第三方库
之前就听说过爬虫,感觉很复杂的样子,但是看到python代码很简短.由于本机已经安装了python2.7 所以就拿来py 文件跑一下想看看效果. 结果各种代码错误.然后根据每个错误去下载对应的依赖项. ...
- python list 和 tuple详解
list------------------------------------------------------------------------ Python内置的一种数据类型是列表:list ...
- 针对nginx,来具体聊聊正向代理与反向代理 (转载)
https://www.sohu.com/a/235704408_468627 先来说说什么是代理服务器? 所谓代理服务器就是位于发起请求的客户端与原始服务器端之间的一台跳板服务器,正向代理可以隐藏客 ...
- 论文解读:3D Hand Shape and Pose Estimation from a Singl RGB Image
本文链接:https://blog.csdn.net/williamyi96/article/details/89207640由于最近做到了一些 3D Hand Pose Estimation 相关的 ...
- centos安装redis 5.0版本的集群
我在本地VM-Centos里安装5.0.5时安装遇到了些问题,参考了Blog:https://www.cnblogs.com/shawhe/p/9548620.html 顺利安装完成. 安装redis ...
- 腾讯云短信 nodejs 接入, 通过验证码修改手机示例
腾讯云短信 nodejs 接入, 通过验证码修改手机示例 参考:腾讯云短信文档国内短信快速入门qcloudsms Node.js SDK文档中心>短信>错误码 nodejs sdk 使用示 ...
- mysql查询之 用户行程的取消率,人流量高峰时段
1.用户行程的取消率 Trips 表中存所有出租车的行程信息.每段行程有唯一键 Id,Client_Id 和 Driver_Id 是 Users 表中 Users_Id 的外键.Status 是枚举类 ...