Apologies this is not a bug but a question seeking direction.
I am having to manage app life cycles and I am following this official guide. As you can see the example uses a StatefulWidget so it has initState and dispose methods available where WidgetsBindingObserver is added and removed respectively.
Since, the guidelines with Bloc is to use StatelessWidget how do we get WidgetsBindingObserver to work, especially where do we add and remove observers?
Hi @schatekar ! 馃憢
It is perfectly fine to use a StatefulWidget. Bloc recommends using StatelessWidgets unless you have some extra UI state to maintain.
Since you would need to add and remove the observer, you'd need a StatefulWidget for that. Same goes for objects which needs to be disposed like PageController, AnimationController to name a few.
Most helpful comment
Hi @schatekar ! 馃憢
It is perfectly fine to use a
StatefulWidget. Bloc recommends usingStatelessWidgets unless you have some extra UI state to maintain.Since you would need to add and remove the observer, you'd need a
StatefulWidgetfor that. Same goes for objects which needs to be disposed likePageController,AnimationControllerto name a few.