DEV Community

Cover image for Generic BLoC Provider
Roberto Huertas
Roberto Huertas

Posted on • Originally published at robertohuertas.com

Generic BLoC Provider

If you're using the BloC pattern to manage the state of your Flutter applications probably you're tired of writing again and again your BLoC providers. I've just published a simple package called Generic BLoC Provider that will help you with that.

Thank God we have generics!

If you're not new to the BLoC pattern probably you have also suffered the boilerplate associated to the BLoC providers.

Maybe you have surrendered to the comodity of copy & paste and you don't care about this, but if you're like me and you hate having repetitive code probably you have been creating your own generic implementation.

It's something easy and it doesn't require a lot of Flutter knowledge to build, but again, whenever you have to start a new project you may find yourself with your old friend copy & paste copying your generic implementation from project to project, and maybe, improving it and mutating it along the way.

And that's a complete waste of time.

That's why I decided to publish a new package doing precisely that, a generic implementation of a BLoC provider naively called generic_bloc_provider.

Learning something new while at it

While I was building this package I also learnt about how to automate the process of analyzing, testing and publishing a Flutter package using Travis CI.

In case you want to learn more about it, please check out my previous post in my blog or in medium. 😀

Some extra features

You can see how to use the package in the Github's repo or in Pub Dartlang.

I've tried to let the user of the package customize some of the behaviors, namely:

  1. the usage of inheritFromWidgetOfExactType vs ancestorInheritedElementForWidgetOfExactType,

  2. the implementation of updateShouldNotify.

Contribute

I hope you find it useful and, of course, feel free to open an issue or, better, a PR with some improvement in the Github's repo.

Enjoy!

--
Originally published at robertohuertas.com on January 21, 2019.

Top comments (0)