RxBloc Intellij Plugin

Nikolay Ivanov
Prime Holding JSC
Published in
3 min readMar 22, 2021

The Business Logic Component (BLoC) pattern is a pattern created by Google that uses Reactive Programming to handle the flow of data within an app.

RxBloc is an ecosystem of dart packages that help implement the BLoC pattern and speed up the development of Flutter apps. If you’re unfamiliar with them, please take a quick look at this article introducing the rx_bloc ecosystem before continuing to read below.

Today’s article is going to look into the IntelliJ Plugin for creating a RxBloc and how by using the plugin you can skip the time for creating the common basics of every BloC plus avoid any annoying typos.

Installation

You can find the plugin in the official IntelliJ and Android Studio marketplace under the name of RxBloc.

Usage

Simply right-click on the File Project view, go to New -> RxBloc Class, give it a name, select if you want to use some of the options:

  • Include default states — this option will let you have 2 additional states in your reactive BLoC — errors & isLoading that are responsible for handling any errors that may occur and keeping the result state of your streams on track.
  • Include null safety — if your project isn’t migrated yet to the latest Flutter & Dart version which supports null safety, please uncheck this option so you can continue to create non-null safety BLoC classes.
  • Include extensions — It’s recommended that you keep your implementation details & declarations out of the BLoC’s body. However, the option is unchecked by default and we do not force you to use it.

Then by clicking the OK button you will see the entire generated boilerplate.

RxBloc Extensions

As mentioned above, we highly recommend that you do not place your implementation details inside the BLoC’s body. One way to achieve this is by using the extensions file. The desired result would bring more code simplicity, easy readability, less repetition, and last but not least help with the single responsibility.

What next?

Since all of our basics are ready, the only thing we’re missing is the RxBlocGenerator, which is used to generate the boilerplate on top of the code you want to write. Make sure it is added as a dependency in your pubspec.yamlfile.

To start the generator, run flutter packages pub run build_runner build, or flutter packages pub run build_runner watchin your console/terminal.

--

--