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);
}
});
}.broadcast
because 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 ...
随机推荐
- 第06组 Beta冲刺(3/5)
队名:拾光组 组长博客链接 作业博客链接 团队项目情况 燃尽图(组内共享) 组长:宋奕 过去两天完成了哪些任务 继续维护后端代码 学习深入python 研究匿名拨打电话问题.套牌多结果处理问题 Git ...
- 解决vs2010按ctrl+f5,调试窗口一闪而过的方法
vs2010调试按F5与按Ctrl+F5有什么区别 Ctrl F5测试运行后不自动推出控制台,直接按F5会自动退出去 解决vs2010按ctrl+f5,调试窗口一闪而过的方法 http://hi.ba ...
- 分布式事务之最终一致性BASE理论
一.事务 事务提供一种机制将一个活动涉及的所有操作纳入到一个不可分割的执行单元,组成事务的所有操作只有在所有操作均能正常执行的情况下方能提交,只要其中任一操作执行失败,都将导致整个事务的回滚.简单地说 ...
- pip3的国内安装源
1,清华源 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualen 2,豆瓣源 pip3 install -i https ...
- Java并发包之阶段执行之CompletionStage接口
前言 CompletionStage是Java8新增得一个接口,用于异步执行中的阶段处理,其大量用在Lambda表达式计算过程中,目前只有CompletableFuture一个实现类,但我先从这个接口 ...
- thinkphp5---安装到宝塔出现Warning: require(): open_basedir错误
使用thinkphp5安装到宝塔的linux上,出现以下错误: Warning: require(): open_basedir restriction in effect. File(/www/ww ...
- [LeetCode] 243. Shortest Word Distance 最短单词距离
Given a list of words and two words word1 and word2, return the shortest distance between these two ...
- LeetCode:四数之和【18】
LeetCode:四数之和[18] 题目描述 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c ...
- tween算法
tween算法 https://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html 参数说明: t: current time:当前时间: ...
- 使用pyinstaller将python打包成exe文件
步骤: 1)win+R 输入cmd打开dos窗口 2)先安装pyinstaller: pip install pyinstaller 3)然后使用cd命令进入项目文件的路径下: 4)再使用命令 ...