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 {
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);
}
});
}
I didn't use .broadcast because it slowed my UI.

Bad state: Stream has already been listened to.的更多相关文章

  1. node中的Stream-Readable和Writeable解读

    在node中,只要涉及到文件IO的场景一般都会涉及到一个类-Stream.Stream是对IO设备的抽象表示,其在JAVA中也有涉及,主要体现在四个类-InputStream.Reader.Outpu ...

  2. Stream探究

    http://segmentfault.com/a/1190000003479884 1. 认识Stream Stream的概念最早来源于Unix系统,其可以将一个大型系统拆分成一些小的组件,然后将这 ...

  3. Java Stream 使用详解

    Stream是 Java 8新增加的类,用来补充集合类. Stream代表数据流,流中的数据元素的数量可能是有限的,也可能是无限的. Stream和其它集合类的区别在于:其它集合类主要关注与有限数量的 ...

  4. 简单了解node stream

    Almost all Node.js applications, no matter how simple, use streams in some manner. 开篇先吓吓自己.画画图,分析分析代 ...

  5. 谈谈stream的运行原理

    害,别误会,我这里说的stream不是流式编程,不是大数据处理框架.我这里说的是stream指的是jdk中的一个开发工具包stream. 该工具包在jdk8中出现,可以说已经是冷饭了,为何还要你说?只 ...

  6. C# 实现 微软WebRequestMethods.Ftp类中的FTP操作功能

    先奉献一个测试地址,ftp内的文件请勿删除,谢谢 FtpEntity fe = "); 由于代码量较多,只抽出一部分,详细代码请移步  ftp://wjshan0808.3vhost.net ...

  7. Trident中的DRPC实现

    一:介绍 1.说明 Storm里面引入DRPC主要是利用storm的实时计算能力来并行化CPU intensive的计算.DRPC的storm topology以函数的参数流作为输入,而把这些函数调用 ...

  8. Trident中使用HBase进行状态管理

    1.使用的类 2.使用HBaseMapState 3.使用状态管理 使用的状态管理还要看Spout StateFactory factory1 = HBaseMapState.opaque(opts1 ...

  9. Trident继承kafka

    1.Kafka涉及的类 上一个类是不透明事务 后一个是完全事务 2.启动服务 3..驱动类 重要的地方是修改了两个部分: 1.数据的来源是kafka 2.第二个是字段的Fields是str packa ...

随机推荐

  1. java下载文件工具类

    java下载文件工具类 package com.skjd.util; import java.io.BufferedInputStream; import java.io.BufferedOutput ...

  2. Unity3D Substance designer Sub 欧洲小镇场景制作视频教程 中文字幕

    大小6.53G,中文字幕 扫码时备注或说明中留下邮箱 付款后如未回复请至https://shop135452397.taobao.com/ 联系店主

  3. jmeter 内存溢出原因及解决方法

    jmeter是一个java开发的开源性能测试工具,在性能测试中可支持模拟并发压测,但有时候当模拟并发请求较大或者脚本运行时间较长时,压力机会出现卡顿甚至报异常————内存溢出, 这里就介绍下如何解决内 ...

  4. 使用expect快速登录线上机器

    背景: 公司登陆线上服务器一般都要经过跳板机才能登陆,过程比较麻烦,如果要频繁登陆某个机器而且机器名不好记很费劲,使用expect自动登陆会方便很多 实现: 使用expect脚本自动登陆: #!/us ...

  5. Python之schedule用法,类似linux下的crontab

    # -*- coding: utf-8 -*- # author:baoshan import schedule import time def job(): print("I'm work ...

  6. Python装饰器之functools.wraps的作用

    # -*- coding: utf-8 -*- # author:baoshan def wrapper(func): def inner_function(): pass return inner_ ...

  7. Win10访问共享文件夹如何取消用户名密码

    win10中,开启guest(来宾)账户的步骤是: 右击win10左下角Windows的图标->计算机管理->计算机管理(本地)->系统工具->本地用户和组->用户-&g ...

  8. [译]为什么在__new __()后总是调用__init __()?

    原文来源: https://stackoverflow.com/questions/674304/why-is-init-always-called-after-new 需要控制新实例的创建时,请使用 ...

  9. FormsAuthentication使用指南,实现登录

    一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到Session中存储的用户基本信息,查看比较他有没有登录和能否访 ...

  10. [LeetCode] 217. Contains Duplicate 包含重复元素

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...