Published in


Converting Cubits to bloc in Flutter

In this article we will discuss about converting or migrating from simple cubits to flutter bloc pattern.

📺 Video Tutorial

In our previous article we discussed about how to create flutter app with the help of simple cubits for state management. Now let’s move towards converting cubits to flutter bloc. The process is very simple and they are listed below as follows.,

  1. Creating States

First let’s start with the states. Creating states for bloc is same as creating states in cubits(no change). Therefore we can create states for our flutter app with bloc pattern as shown below.,

2. Creating Events

While dealing with cubits, we won’t have separate file for handling events. But in bloc architecture, there will be a separate file which will hold all events (for example 👇)

3 Mapping events to states

Now we have events and states written down separately, let’s map corresponding events to the corresponding states and get the app working✨.

Now in order to trigger the event, (Increment/Decrement), we make use of add() method.

BlocProvider.of<CalculatorBloc>(context).add(Increment(Counter: currentValue+1));BlocProvider.of<CalculatorBloc>(context).add(Increment(Counter: currentValue-1));

Well that’s it. 🥳🎉

This is how we can convert cubits to bloc in 3 simple steps.

Check out all my Flutter related blogs here.,👇



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store