bloc-cubit

Guides Flutter state management decisions and implementation using the bloc and flutter_bloc packages.

14.0k|1.2k|Updated Oct 30, 2025
One-click install
npx skills add https://github.com/andrewyng/context-hub --skill bloc-cubit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bloc-cubit
Source: https://github.com/andrewyng/context-hub/tree/main/content/flutter/skills/state-management/bloc-cubit
Command: npx skills add https://github.com/andrewyng/context-hub --skill bloc-cubit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Flutter developers often struggle to choose between Bloc and Cubit, mismanage bloc lifecycles, or wire UI widgets incorrectly, leading to memory leaks, unnecessary rebuilds, and tangled architecture.

Core Features & Use Cases

  • Decision Guidance: Clear rules for choosing Cubit for simple method-based state updates versus Bloc for event-driven flows with loading, success, and failure transitions.
  • Lifecycle & UI Binding Rules: Covers when to call close(), how BlocProvider manages disposal, and when to use BlocBuilder, BlocListener, BlocConsumer, and BlocSelector.
  • Testing & Pitfall Avoidance: Provides testing patterns for blocs and cubits plus a checklist of common mistakes like duplicate dependencies and app-wide god blocs.
  • Use Case: When building a checkout flow in a Flutter app, use this Skill to model it as an event-driven Bloc with explicit states, wire it via BlocProvider, and write transition tests.

Quick Start

Ask the agent to help you implement state management for a Flutter feature using Bloc or Cubit and explain which one fits your use case.

Frequently Asked Questions about bloc-cubit

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

FAQPage Schema
How do I choose between Bloc and Cubit in Flutter?

Choose Cubit for simple method-based state updates like counters, toggles, and form flags. Choose Bloc when user actions should be explicit events with loading, success, and failure transitions, such as auth, pagination, or checkout flows.

Do I need both bloc and flutter_bloc packages in a Flutter app?

No, flutter_bloc depends on bloc and brings it in transitively, so adding only flutter_bloc is sufficient for Flutter apps. Add bloc alone only for Dart-only projects without Flutter widgets.

When should I call close() on a Bloc or Cubit?

Call close() only on blocs and cubits you create manually outside the widget tree. Instances owned by BlocProvider or MultiBlocProvider are disposed automatically by Flutter and must not be closed manually.

What is the difference between BlocBuilder and BlocListener?

BlocBuilder rebuilds the widget when state changes, while BlocListener reacts to state changes without rebuilding, typically for side effects like navigation or snackbars. Use BlocConsumer when you need both behaviors in one place.

How do I test a Bloc or Cubit in Flutter?

Test a Cubit by calling its methods and asserting the emitted states, and test a Bloc by adding events and asserting the transition sequence. Mock repositories at the boundary rather than inside the bloc logic.