WHAT IS FLUTTER BLOC PATTERN?

Muhammad Ibrahim
2 min readApr 1, 2021

In this fast escalating era, fortunately there are many programming tools available to developers who want to create them. Among these tools there is Flutter, which has distinguished itself lately.

The very first question that arises is what is Bloc Pattern?

BLoC (Business Logic Components) pattern is developed by Google for IOs and ANDROID USERS to manage the state within the application. BLoC sepatares business logic from your UI element that way your code is cleaner and easier to manage. We give BLoC an event as an Input data, the BLoC runs the necessary algorithm and returns it as State. There are some core terminologies in the world of Flutter Bloc Pattern which are;

EVENTS

Events are what we sent to the Bloc to be acted upon. Events can be triggered from some actions happening in the software. The BLoC executes the logic on the basis of the events sent to it.

STATES

When the logic is executed the bloc needs to return a state. A state is something that can change within an application. Whether it is on the actual UI or like the authentication being received.

STREAM

A Stream is a sequence of things or data. In simplified way, we can say that it’s a like a water pipe. From the one side of the pipe we pour water and it gets transmitted to other side to the user.

STREAM BUILDER

A stream builder is a widget that can convert user defined objects into a stream. Apps nowadays are highly asynchronous; stream builder listens to the events flowing through the stream. For every new event, it rebuilds the sentence giving them the latest event to work with.

BLoC BUILDER

Once a state has been received, it needs to be handled, and widgets need to be rebuilt accordingly. This is what the BLoc Builder is for. Whenever a state change happens, it will rebuild all the child widgets with the new state information.

BLoC PROVIDER

The BLoC provider is that significant widget of the flutter which creates and provides blocs to all its children this is also known as dependency injection widget so that a single can be provided to multiple widgets. BLoC provider creates a single instance of the BLoC using the function

WHY FLUTTER?

* A fast and expressive way for developers to build native apps. This is because apps and interfaces built with Flutter are built from a single codebase, compiled directly to native arm code, use GPU, and can access platform APIs and services.

* Flutter is engineered for high developer velocity.

* Flutter also ships with a rich set of customizable widgets, all built from a modern reactive framework.

--

--

Muhammad Ibrahim

I'm a flutter developer, having active working experience of more than 2 years developing mobile apps.