Bloc Library v1.0.0 is here! šŸŽ‰

Felix Angelov
Flutter Community
Published in
4 min readOct 21, 2019

At long last, v1.0.0 is here! Itā€™s been just over one year since the bloc package was released into the wild. Since then the community has grown tremendously and has played a significant role in shaping the library.

Before delving into whatā€™s changed, I want to give a big thank you to everyone who has contributed whether it be through opening issues, improving documentation, adding feature requests, or simply reaching out on gitter or via email with feedback. I couldnā€™t have made it this far without your help!

Now letā€™s jump into whatā€™s changed!

Alignment with the Core Dart Stream/Sink API

What started off as a rename request from Bernardo Ferrari turned into a much larger discussion of the core bloc api (full discussion). Thanks to the feedback of many members of the community including Honza Bittner, Jonathan White, Audrius Karosevicius, Remi Rousselet, and Brian Egan we decided to make some adjustments to the bloc api in order to align with the core stream primitives and deliver a more consistent and familiar developer experience.

Bloc as a Stream<State>

In v1.0.0 of the bloc library, all blocs are Streams. That means we no longer need Stream<State> get state. Developers can now listen to a blocā€™s state stream directly from the bloc.

This also enabled us to repurpose the bloc state property to return the value of the state, removing the need for a currentState property.

These changes were done in hopes of eliminating any previous confusion of the difference between bloc.state and bloc.currentState. Working with a blocā€™s state stream should now feel very intuitive, especially to those coming from StreamControllers and Subjects.

Bloc as a Sink<Event>

In v1.0.0 of the bloc library, all blocs are now Sinks. This means we can start using the traditional add sink api in order notify the bloc of a new event instead of dispatch.

In addition, dispose was deprecated in favor of close.

Not only do these changes align the bloc api with existing standards, but we also get the added benefit of the dartanalyzer showing warnings if we forget to call close on our blocs (BlocProvider still does this automatically).

Testing Improvements

v1.0.0 of the bloc library also includes a new package: bloc_test. This package is still in the early stages, but will be home to a suite of testing helpers specifically designed for the bloc library.

Currently, the package allows us to easily stub a blocā€™s state stream via whenListen (shoutout to Brian Egan for the suggestion).

Expect additional testing helpers to be including in the coming weeks!

New Domain and Publisher

The bloc library official documentation can now be found at https://bloclibrary.dev!

*https://felangel.github.io/bloc will redirect automatically.

In addition, all of the official bloc library packages can now be found under the bloclibrary.dev publisher on pub.dev.

Now on Github Sponsors šŸ’–

Iā€™m very lucky to have just been accepted into the Github Sponsors beta program. So if you like the bloc library, or any of my other open source projects, consider sponsoring me (tiers start as low as $2 / month) to show your support. šŸ™

You can also support me by ā­ļø the repository, or šŸ‘ for this story, thanks!

--

--