Search⌘ K

Bloc and Cubit

Explore the core concepts of Bloc and Cubit widgets in Flutter's BLoC library. Understand how Blocs manage complex states using events and streams, while Cubits provide simpler state management with less boilerplate. Learn their differences and practical use cases for effective state handling.

The flutter_bloc library includes two state management tools: Blocs and Cubits. While they have many similarities, they also have some significant differences. Blocs manage complex state changes, whereas Cubits manage simpler state changes. Cubits contain less boilerplate code than Blocs, making them more suitable for simple use cases.

Blocs

Blocs are the foundation of the BLoC library. A Bloc is in charge of managing a state and exposing it to the widget tree. It receives a stream of events, processes them, and then updates the stream of states.

For the Bloc syntax, we define a class that extends the Bloc class and accepts two type parameters: event type and state type. We then use the ...