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 ...
随机推荐
- MacBook Air在macOS Mojave和macOS Seirra系统下使用Loopback在OBS Studio推流时输出系统软件声音
转载请标注原地址:https://www.cnblogs.com/lixiaojing/p/11440533.html 运行环境: Loopback破解版获取: https://pan.baidu.c ...
- NGINX Cache Management (.imh nginx)
In this article, we will explore the various NGINX cache configuration options, and tips on tweaking ...
- [Angular] ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'name' of undefined
在数据请求完成通过 ionViewDidLoad 展示页面的时候 报错误 : ERROR Error: Uncaught (in promise): TypeError: Cannot read pr ...
- mysql实现oracle存储过程默认参数
我们都知道oracle存储过程支持为参数设置默认值,这样即使存储过程升级,原来的调用也可以不受影响.但是mysql不支持,mariadb也没有支持(截止10.4也是如此).但是这一限制会导致升级麻烦重 ...
- vue---发送数据请求的一些列的问题
使用vue做数据请求,首先考虑的是封装请求方法request.js import axios from 'axios' import Qs from 'qs' // 创建一个axios实例 const ...
- Spark资源调度及任务调度
1. 资源分配 通过SparkSubmit进行提交应用后,首先会创建Client将应用程序(字节码文件.class)包装成Driver,并将其注册到Master.Master收到Client的注册请 ...
- 某表中字段值存在多个Gid逗号分开 取值拆分每个gid SQL多个逗号隔开的取值
存在值信息 表值函数实现: --实现split功能 的函数 拆分 逗号分开的多个值 ),)) )) as begin declare @i int set @SourceSql=rtrim(ltrim ...
- SDN实验---Ryu的安装
一:Ryu是主流SDN开源控制器之一 (一)推文(摘录自) https://ryu.readthedocs.io/en/latest/ https://www.sdnlab.com/1785.html ...
- 日志分类以及TFIDF
TF的概念是Term Frequent,是一个单词出现的频率,是一个局部概念,就是这个单词在指定文件中出现的频率,公式如下: 但是呢,这个TF其实很没有说服力,比如the,a之类的频率很高,但是其实不 ...
- 根据本地/服务器时间获取指定时区时间 new Date指定时区时间
1.代码 function getTimeByTimeZone(timeZone){ var d=new Date(); localTime = d.getTime(), localOffset=d. ...