Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad state: Stream has already been listened to. #1

Open
val-creare opened this issue Oct 15, 2021 · 2 comments
Open

Bad state: Stream has already been listened to. #1

val-creare opened this issue Oct 15, 2021 · 2 comments

Comments

@val-creare
Copy link

val-creare commented Oct 15, 2021

Using this example as is and starting a connection, connection fails on tcp_bloc.dart line 40 : _socket = await _socketConnectionTask!.socket;. The error is Unhandled exception: Bad state: Stream has already been listened to. #0 _StreamController._subscribe (dart:async/stream_controller.dart:635:7) #1 _ControllerStream._createSubscription (dart:async/stream_controller.dart:786:19) #2 _StreamImpl.listen (dart:async/stream_impl.dart:473:9) #3 _Socket.listen (dart:io-patch/socket_patch.dart:2026:31).

I'm using Flutter 2.5.2 and Dart 2.14.3. Any hint on how to fix this issue?

@JulianAssmann

@JulianAssmann
Copy link
Owner

You can try stream.toBroadcastStream()

@val-creare
Copy link
Author

Thanks for your suggestion. I tried it and wasn't able to make it work. I'm shifting to a slightly different solution where I'm not using StreamSubscription and ConnectionTask. Instead, I'm defining _socket in the mapEventToState function as final _socket = await Socket.connect(YOUR_SERVER_IP, YOUR_SERVER_PORT);. Seems to work so far, but of course other things are not working now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants