Flutter State Management (Bloc)- Week 1

 

BLoc(Business logic)


A Bloc is a more advanced class which relies on events to trigger state changes rather than functions. Bloc also extends BlocBase which means it has a similar public API. Blocs receive events and convert the incoming events into outgoing states.




Why Bloc?

Bloc makes it easy to separate presentation from business logic, making your code fast, easy to test, and reusable.

When building production quality applications, managing state becomes critical.

As developers we want to:

  • know what state our application is in at any point in time.
  • easily test every case to make sure our app is responding appropriately.
  • record every single user interaction in our application so that we can make data-driven decisions.
  • work as efficiently as possible and reuse components both within our application and across other applications.
  • have many developers seamlessly working within a single code base following the same patterns and conventions.
  • develop fast and reactive apps.

Bloc was designed to meet all of these needs and many more.

There are many state management solutions and deciding which one to use can be a daunting task. There is no one perfect state management solution! What's important is that you pick the one that works best for your team and your project.

Bloc was designed with three core values in mind:

  • Simple: Easy to understand & can be used by developers with varying skill levels.
  • Powerful: Help make amazing, complex applications by composing them of smaller components.
  • Testable: Easily test every aspect of an application so that we can iterate with confidence.

Overall, Bloc attempts to make state changes predictable by regulating when a state change can occur and enforcing a single way to change state throughout an entire application.


Overview

Bloc consists of several pub packages:

  • bloc - Core bloc library
  • flutter_bloc - Powerful Flutter Widgets built to work with bloc in order to build fast, reactive mobile applications.
  • angular_bloc - Powerful Angular Components built to work with bloc in order to build fast, reactive web applications.
  • hydrated_bloc - An extension to the bloc state management library which automatically persists and restores bloc states.
  • replay_bloc   - An extension to the bloc state management library which adds support for undo and redo.






Post a Comment

Previous Post Next Post