I am new to flutter and bloc. As a matter of fact, I have just recently started using cubit. For learning purposes, I have created a simple app in which I use cubit for bloc functionality. In all the examples I found online, they suggest disposing the bloc instance in the UI. However, I didn't find something similar when it comes to cubit. So, my question is: Do I need to dispose the cubit instances and how? It worths mentioning here that I am using MultiBlocProvider.
Asked
Active
Viewed 6,327 times
1 Answers
13
Bloc extends Cubit and Cubit extends Stream. Like any Stream in Dart it needs to be disposed when it is not necessary, and it has close
method to do so.
This method will be executed automatically if you are using BlocProvider

Pavel Shastov
- 2,657
- 1
- 18
- 26
-
Thank you for you answer! This means that I don't have to create a @dispose method. Is this right? – johnweak Sep 22 '20 at 05:56
-
2Correct. MultiBlocProvider will handle disposing – Pavel Shastov Sep 22 '20 at 07:11
-
@johnweak do you mind marking post as an answer if it helped? – Pavel Shastov Sep 25 '20 at 13:04
-
But if I want to, for example, cancel a subscription before close (or remove a listener). Should I override the close method (calling super.close(), of course) ? – Caio Santos Apr 03 '21 at 19:50
-
2@CaioSantos Yes. Subscriptions that are defined inside Cubit class won't be closed otherwise – Pavel Shastov Apr 04 '21 at 06:38