Announcing — Dash

Bloc provider made easy

Hi folks, today I am very happy to announce Dash! A new way to provide and dispose bloc. In this article I will explain why this package was created and the problem that it tries to solve.

Dash

The problem…

When we began to use BloC in our Flutter project we opted to create a bloc provider class, which responsibility was, of course, to provide blocs. This class was extending from InheritedWidget class, but soon we realized that we were having a problem to close/dispose our bloc’s streams because it has no control of widget lifecycle.

After some time we learned that a good approach to close our bloc's stream would be making our bloc provider class stateful by extending it from StatefulWidget class which allow through overriding dispose() method, close our streams.

Nice! BUT!

This solution was working well until we found that extending our provider class from StatefulWidget class actually was increasing the cost of providing our bloc class because of its time complexity. In other words, it increased from Constant Time(InheritedWidget) to Linear Time(StatefulWidget).

Ok! And now?

The solution was to create a Provider class that extends from InheritedWidget (which could provide our bloc class with constant time) and another BlocProvider class that extends from StatefulWidget (which allow us to close our bloc's streams through overriding dispose method). You can find more about this approach here.