Hi, the dispose method is not called in bloc, I have to call it myself in the stfl widget.
Hey @1AlexFix1 馃憢
This is working as intended. It鈥檚 up to developers to call dispose on the bloc. In most cases you should call dispose in the dispose override of a StatefulWidget like you mentioned.
Hey @1AlexFix1 馃憢
This is working as intended. It鈥檚 up to developers to call dispose on the bloc. In most cases you should call dispose in the dispose override of a StatefulWidget like you mentioned.
Why don't change BlocProvider InheritedWidget to stfl, this will solve the problem. After all, if you yourself do not call for disposal on the unit, then
The block will not call for recycling and, accordingly, does not stop the operation of _eventSubject.close ();
_stateSubject.close ();
I didn鈥檛 find it in the documentation from the first pass, which can be a problem for newbies, as in normal examples BlocProvider is a stfl widget, and there it pulls itself, which can cause some difficulties for people), at least it can write about is it in the readme?
BlocProvider is an InheritedWidget and is just one way to provide a bloc to a Widget. It is not required that you use BlocProvider and instead you can manually inject blocs via constructor or use other dependency injection solutions (which would still require you to manually dispose). Furthermore, you might want to use multiple BlocProviders in different parts of your application with the same bloc. Automatically disposing would break the application in that case because the streams would be closed when one BlocProvider was disposed while the other provider could still be active.
In any case, you can check out the flutter_bloc_extensions package which exports a DisposableBlocProvider that does exactly what you're asking for 馃憤
I added dispose to the bloc package README as you suggested since I agree it should be in the bloc interface section 馃憤
Thanks for the feedback!
BlocProvideris anInheritedWidgetand is just one way to provide a bloc to a Widget. It is not required that you useBlocProviderand instead you can manually inject blocs via constructor or use other dependency injection solutions (which would still require you to manually dispose). Furthermore, you might want to use multipleBlocProvidersin different parts of your application with the same bloc. Automatically disposing would break the application in that case because the streams would be closed when oneBlocProviderwas disposed while the other provider could still be active.In any case, you can check out the flutter_bloc_extensions package which exports a
DisposableBlocProviderthat does exactly what you're asking for 馃憤I added
disposeto the bloc package README as you suggested since I agree it should be in the bloc interface section 馃憤Thanks for the feedback!
Yes, you are right, if one block fits into two blocProvider, then it will be bad) I understand that the case when we need a block in two blocProvider is when you click on the next screen where the same block is needed. No, I understand how it works. Thanks for adding to the readme, this will definitely help =)
Most helpful comment
Yes, you are right, if one block fits into two blocProvider, then it will be bad) I understand that the case when we need a block in two blocProvider is when you click on the next screen where the same block is needed. No, I understand how it works. Thanks for adding to the readme, this will definitely help =)