How to maintain Flutter Global BloC state using Provider on Hot Reload?

Posted by Ramesh Singh | Updated on

If you want to maintain Flutter Global BloC state using Provider on Hot Reload. I was facing the same problem. Inherited widgets make it hard disposing bloc’s resources. Stateful widget, on the other hand, allows disposing, but in the implementation you’re using it doesn’t persist the bloc in the state causing state loss on widgets rebuild.

After some experimenting I came up with an approach that combines the two:

Bloc holder creates bloc in createState() and persists it. It also disposes bloc’s resources in dispose().


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers