bloc

Guide Flutter state management implementation and testing with bloc and flutter_bloc libraries.

Updated Jun 30, 2025
One-click install
npx skills add https://github.com/hnvcam/teno_mindmap --skill bloc-hnvcam
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bloc
Source: https://github.com/hnvcam/teno_mindmap/tree/main/.qwen/skills/bloc
Command: npx skills add https://github.com/hnvcam/teno_mindmap --skill bloc-hnvcam

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a comprehensive guide to implementing, structuring, and testing state management in Flutter applications using the popular bloc and cubit libraries, ensuring maintainable and scalable code.

Core Features & Use Cases

  • State Management Patterns: Learn best practices for Cubit vs. Bloc, state modeling (sealed classes vs. single class with enum), and naming conventions.
  • Architecture Guidance: Understand the recommended three-layer architecture (Presentation, Business Logic, Data) and inter-layer communication.
  • Flutter Bloc Widgets: Master the usage of BlocProvider, BlocBuilder, BlocListener, and other essential widgets for connecting UI to state.
  • Testing: Implement robust unit tests for Cubits and Blocs using the bloc_test package.
  • Use Case: When building a new feature in a Flutter app that requires complex user interactions and data synchronization, use this Skill to set up the state management logic following established patterns and best practices.

Quick Start

Use the bloc skill to create a new Cubit for managing user authentication state.

Frequently Asked Questions about bloc

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Flutter state management using the bloc library?

Flutter state management using the bloc library should follow a three-layer architecture: Presentation, Business Logic, and Data layers. This separation ensures maintainable code and clear inter-layer communication patterns for complex applications.

What is the difference between Cubit and Bloc in Flutter?

The difference between Cubit and Bloc in Flutter is their complexity and event handling. Cubit is simpler and uses methods to emit states, while Bloc uses events and event transformers, making it suitable for more complex state management and logic tracking.

How do I test Cubit and Bloc state changes in Flutter?

To test Cubit and Bloc state changes in Flutter, use the bloc_test package. It provides robust testing capabilities to verify state sequences and ensure your business logic correctly emits expected state transitions during unit tests.

Should I use sealed classes or enums for Flutter bloc state modeling?

For Flutter bloc state modeling, you can use either sealed classes or a single class with enums. Sealed classes offer type safety and distinct state instances, while single class with enum tracks status changes within one state object, depending on complexity.

Which Flutter widgets connect UI components to bloc state?

Flutter widgets that connect UI to bloc state include BlocProvider, BlocBuilder, and BlocListener. BlocProvider handles dependency injection, BlocBuilder rebuilds UI on state changes, and BlocListener triggers side effects like navigation or showing snackbars.

When should I not use the Bloc pattern for Flutter state management?

You should not use the Bloc pattern for Flutter state management when your feature requires minimal user interaction and simple data synchronization. For simple state needs, Cubit offers a lighter approach, avoiding unnecessary event mapping boilerplate.