bloc-cubit
What it does
This skill explains how to organize data and screen changes in Flutter apps using the Bloc and Cubit tools. It is for developers building Flutter apps who want clear, testable state handling.
When to use it
- ✓When you build a Flutter app and need to manage changing screen data.
- ✓When you are choosing between Bloc and Cubit for a feature.
- ✓When you want to set up tests for Flutter state logic.
Skill link
https://github.com/andrewyng/context-hub/blob/main/content/flutter/skills/state-management/bloc-cubit/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“I want to set up Bloc state management for the checkout screen in my Flutter app.”
5 new skills a week. 1 minute to read.
How it works
The skill gives a simple rule: use Cubit for direct updates and Bloc for event-driven steps. It then shows the setup and structure to follow in the code.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Flutter Bloc/Cubit State Management
Use this skill when building Flutter state management with bloc and flutter_bloc.
Core Rule
- Use
Cubitfor simple, direct state updates. - Use
Blocfor event-driven flows, transitions, and replayable business logic. - Use
blocin Dart-only projects. - Use
flutter_blocin Flutter apps when you need widgets likeBlocProvider,BlocBuilder, orBlocListener. - If you install
flutter_bloc, you do not need to addblocseparately in a Flutter app becauseflutter_blocdepends on it.
Decision Guide
Choose Cubit when:
- state changes are simple method calls
- you do not need events
- the feature is local and low complexity
- examples include counters, toggles, filters, form flags, and theme mode
Choose Bloc when:
- user actions should be modeled as explicit events
- the flow has loading, success, and failure transitions
- the logic benefits from clear state machines
- examples include auth, pagination, checkout, sync, and multi-step workflows
Required Project Setup
For Dart-only code:
- add
bloc - do not add
flutter_blocunless Flutter widgets are needed
For Flutter UI code:
- add
flutter_bloc - let it bring
bloctransitively - use
BlocProviderat the feature boundary - use
BlocBuilderfor rebuilds andBlocListenerfor side effects
Implementation Pattern
Prefer this structure:
- repository or service owns I/O
- bloc/cubit owns state and orchestration
- UI only dispatches actions and renders state
Keep state immutable.
Keep events explicit when using Bloc.
Keep one bloc or cubit per feature responsibility.
Lifecycle Rules
- Close manually created blocs and cubits with
close(). - Do not manually close instances owned by
BlocProvider. - Use
BlocProviderorMultiBlocProviderto let Flutter manage disposal. - If you create a bloc/cubit with
newor a constructor outside the widget tree, you own its lifecycle.
UI Binding Rules
Use BlocBuilder when the widget should rebuild from state.
Use BlocListener when the widget should react without rebuilding.
Use BlocConsumer only when both are needed in one place.
Use buildWhen and listenWhen when rebuilds or listeners need narrowing.
Use BlocSelector when only one field should drive rebuilds.
Testing Rules
- Test
Cubitby calling methods and asserting emitted states. - Test
Blocby adding events and asserting the transition sequence. - Mock repositories at the boundary, not inside the bloc logic.
- Test side effects separately from rendering logic.
Common Pitfalls
- Do not put network calls directly in widgets.
- Do not use
Blocfor trivial local state. - Do not add both
blocandflutter_blocin a Flutter app when onlyflutter_blocis needed. - Do not forget
close()for manually managed instances. - Do not emit duplicate states unless the transition is meaningful.
- Do not let a single bloc grow into an app-wide dumping ground.
What To Prefer In Answers
When writing code or advising on design:
- show the smallest working Bloc or Cubit first
- mention why Bloc or Cubit was chosen
- mention whether the dependency should be
blocorflutter_bloc - include cleanup and testing notes if lifecycle is manual
- keep examples aligned with the current Flutter state management docs and the bloc package docs
Minimal Reference Checklist
bloc= core logic packageflutter_bloc= Flutter UI integration packageCubit= method-based updatesBloc= event-based transitions- manual creation = manual
close() - provider-owned instance = no manual
close()
FAQ
What is the difference between Bloc and Cubit?
Cubit handles simple direct updates, while Bloc models user actions as explicit events.
Do I need both packages in a Flutter app?
Usually no. The flutter_bloc package brings in the core bloc package on its own.
Is this for normal Dart projects?
For Dart-only projects, the skill suggests the bloc package without the Flutter widget package.
Details
Original description by the author
Use when working with Flutter Bloc/Cubit state management. Covers when to choose Bloc vs Cubit, how to use bloc and flutter_bloc together, lifecycle, testing, and safe defaults.
repo: andrewyng/context-hub
Popularity
- GitHub stars
- 14k
- Ranking position
- #11269
- License
- MIT
- Updated
- 5/31/2026
Comments
- …
More skills from this repository
get-api-docs
14kHelps your agent fetch current documentation for third-party APIs and libraries before writing code, instead of relying on old memory.
riverpod
14kTeaches your agent how to manage Flutter app state with Riverpod, covering providers, async data, and testing, with sensible defaults for each case.
document-extraction
14kHelps your agent read PDFs, images, and spreadsheets, turn them into clean text, and pull out fields like invoice totals using LandingAI's ADE service.
document-workflows
14kHelps your agent build repeatable pipelines that process many documents at once, prepare them for search tools, and load results into a database.
Similar skills
android-clean-architecture
280kMakes your agent organize Android projects efficiently. It structures the code to make maintenance and new feature development easier.
compose-multiplatform-patterns
280kHelps your agent use Compose Multiplatform and Jetpack Compose patterns in KMP projects, covering state, navigation, theming, and performance.
dart-flutter-patterns
280kMakes your agent write code for Dart and Flutter apps. It uses modern patterns to create robust and manageable apps.