Bloc: Must wait for first Event done before start second Event

Created on 19 Apr 2019  路  2Comments  路  Source: felangel/bloc

Describe the bug
I cannot start 2 Events simultaneously. Must wait for first Event done before start second Event.

To Reproduce
Steps to reproduce the behavior:

  1. Create a sample to download file. I dispatch EventDownloadStart to the DownloadBloc in order to start downloading. Then in main UI, I receive StateDownloadProgress(double progress).
  2. Touch on button Stop downloading to dispatch EventDownloadStop.
  3. Watch to log and realize there is no log of EventDownloadStop yet but download is still in progress. Until download is done then I see the log of EventDownloadStop.

Expected behavior
It seems Bloc must wait for first Event done before can be able to process next Event. But I hope Bloc can also process second event simultaneously.

Additional context
Here is the sample app: https://drive.google.com/open?id=1WiUxT_danFVBSLwZmdxQha_mAEDKtxAU

question

Most helpful comment

Hey @anticafe 馃憢

Thanks for reporting this and linking to the example app! I鈥檒l take a look later today 馃憤

All 2 comments

Hey @anticafe 馃憢

Thanks for reporting this and linking to the example app! I鈥檒l take a look later today 馃憤

Hi @anticafe,

I was able to achieve the desired functionality by modifying the download_bloc to maintain a StreamSubscription for the download progress instead of using await and blocking the mapEventToState loop.

If you update your bloc and flutter_bloc versions

bloc: ^0.12.0
flutter_bloc: ^0.11.0

then you can copy this version of download_bloc.dart into your application and it should work as expected.

You can also check out the flutter_bloc_with_stream example app for a simplified version.

In general, if you await on a stream in mapEventToState then you are blocking the event loop until the stream is closed.

Hope that helps and great question! 馃挴

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhwilly picture nhwilly  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

clicksocial picture clicksocial  路  3Comments

ricktotec picture ricktotec  路  3Comments

rsnider19 picture rsnider19  路  3Comments