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

[web] Bad state: stream has already been listened too #64

Closed
sarbogast opened this issue Mar 15, 2022 · 11 comments
Closed

[web] Bad state: stream has already been listened too #64

sarbogast opened this issue Mar 15, 2022 · 11 comments
Labels
bug Something isn't working web Platform web

Comments

@sarbogast
Copy link

On my web app, I have 2 different screens where I want to use MobileScanner. Both are stateful widgets where I initialize the controller in the state, and dispose it in the state's dispose() function.

When I use the scanner in the first screen, everything works fine. Then I switch to the other screen and I get this error:

======== Exception caught by flutter web plugins ===================================================
The following StateError was thrown during a framework-to-plugin message:
Bad state: Stream has already been listened to.

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
dart-sdk/lib/async/stream_controller.dart 676:7                               [_subscribe]
dart-sdk/lib/async/stream_controller.dart 827:19                              [_createSubscription]
dart-sdk/lib/async/stream_impl.dart 473:9                                     listen
packages/flutter_web_plugins/src/plugin_event_channel.dart 136:38             _listen
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1685:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 159:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 465:9                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
====================================================================================================

======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel dev.steenbakker.mobile_scanner/scanner/event:
MissingPluginException(No implementation found for method listen on channel dev.steenbakker.mobile_scanner/scanner/event)

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
packages/flutter/src/services/platform_channel.dart 175:7                     _invokeMethod
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1685:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 159:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 601:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
====================================================================================================

@Adeel-Sultan
Copy link

On my web app, I have 2 different screens where I want to use MobileScanner. Both are stateful widgets where I initialize the controller in the state, and dispose it in the state's dispose() function.

When I use the scanner in the first screen, everything works fine. Then I switch to the other screen and I get this error:

======== Exception caught by flutter web plugins ===================================================
The following StateError was thrown during a framework-to-plugin message:
Bad state: Stream has already been listened to.

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
dart-sdk/lib/async/stream_controller.dart 676:7                               [_subscribe]
dart-sdk/lib/async/stream_controller.dart 827:19                              [_createSubscription]
dart-sdk/lib/async/stream_impl.dart 473:9                                     listen
packages/flutter_web_plugins/src/plugin_event_channel.dart 136:38             _listen
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1685:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 159:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 465:9                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
====================================================================================================

======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel dev.steenbakker.mobile_scanner/scanner/event:
MissingPluginException(No implementation found for method listen on channel dev.steenbakker.mobile_scanner/scanner/event)

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
packages/flutter/src/services/platform_channel.dart 175:7                     _invokeMethod
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1685:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 159:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 601:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
====================================================================================================

Yes I'm facing same issue.
If anyone have solution , please share asap.

@EricRode
Copy link
Contributor

Same problem here

@Antoni-Czaplicki
Copy link
Contributor

Fixed in #76, waiting for merge

@Adeel-Sultan
Copy link

@juliansteenbakker please merge new update and also update this package as well.

@Adeel-Sultan
Copy link

@Antoni-Czaplicki owner not merging your request, we have used this package and still facing this issue.
can you please help ?

@juliansteenbakker
Copy link
Owner

Thanks for reporting. The suggested answer is depending on an external library which i rather not have. I am looking for a solution without the need of an external library. We just need to check wether the stream is already listened too.

@EricRode
Copy link
Contributor

EricRode commented Apr 8, 2022

I found a solution to this problem. If you change
StreamController controller = StreamController(); to
StreamController controller = StreamController.broadcast();
there is no bad state error anymore. But I have the problem that I am just able to scan one time when I restarted the scanner (on the first time I can scan as many as I want but on the next times I can just scan one time, don't know what the problem is.) No error is displayed.

@EricRode
Copy link
Contributor

EricRode commented Apr 8, 2022

I had the problem because allowDuplicates was set to false but I was scanning the same code. So My solution above solves the issue.

@dzero1
Copy link

dzero1 commented Apr 21, 2022

Still I'm getting this problem. I'm using the latest version.

Try on: https://flutlab.io/sandbox/cd165080-8a01-4925-b1f8-6e74cf288f39
To recreate, Press Scan button. Go back page without scaning. Go to scan page again.
(This online IDE doesn't allow to read camera. But you can see the console to check the error)

@Adeel-Sultan
Copy link

Still I'm getting this problem. I'm using the latest version.

Try on: https://flutlab.io/sandbox/cd165080-8a01-4925-b1f8-6e74cf288f39 To recreate, Press Scan button. Go back page without scaning. Go to scan page again. (This online IDE doesn't allow to read camera. But you can see the console to check the error)

Please update your pubspace.yaml file
mobile_scanner:
git:
url: https://github.com/juliansteenbakker/mobile_scanner

@dzero1
Copy link

dzero1 commented Apr 22, 2022

Thanks. That helps me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working web Platform web
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants