Bloc: Dispose multiple blocs

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

Hello @felangel,

first, thank you for this great package! It really makes implementing the BLoC pattern so much easier.

Now to my question:

  • Is it possible to dispose multiple blocs at once? This would be really useful when logging a user out of a app.

In my current project I have multiple blocs listening to different firestore collections. When a user presses the logout button it should cancel all the stream subscriptions to firebase. Do you have a solution for that?

question

Most helpful comment

Thanks for your quick reply. I resolved my issue in the meantime.

I was calling FirebaseAuth.instance.singOut() before my blocs (which had open streams to firestore) were disposed. This triggered a Exception (com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.) because I logged out of Firebase before I cancelled my subscriptions.

All 2 comments

Hi @anatter 馃憢
Thanks for opening an issue and for the positive feedback!

Regarding your question, each bloc is independent and needs to dispose its own subscriptions when it is disposed (similar to a StatefulWidget). Can you please share a sample app with the problem you鈥檙e describing just so that I have a better understanding of your use-case? Thanks!

Thanks for your quick reply. I resolved my issue in the meantime.

I was calling FirebaseAuth.instance.singOut() before my blocs (which had open streams to firestore) were disposed. This triggered a Exception (com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.) because I logged out of Firebase before I cancelled my subscriptions.

Was this page helpful?
0 / 5 - 0 ratings