flutter-bloc-state-management
Standardizes BLoC/Cubit state management, async events, and UI integration in Flutter apps.
Install
mkdir -p .claude/skills/flutter-bloc-state-management && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16136" && unzip -o skill.zip -d .claude/skills/flutter-bloc-state-management && rm skill.zipInstalls to .claude/skills/flutter-bloc-state-management
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Implement BLoC/Cubit state management correctly in Flutter. Use when writing, modifying, reviewing, or testing any BLoC, Cubit, state, or event file.Key capabilities
- →Define events using @freezed
- →Define states using @freezed
- →Implement BLoC to map events to states
- →Connect UI using BlocBuilder for rebuilds
- →Connect UI using BlocListener for side effects
- →Test BLoC with blocTest
How it works
This skill guides the implementation of BLoC/Cubit state management in Flutter by defining events and states, mapping them in BLoC, and connecting to the UI for rendering and side effects.
Inputs & outputs
When to use flutter-bloc-state-management
- →Implement BLoC state
- →Handle async UI events
- →Write bloc tests
About this skill
BLoC State Management
Priority: P0 (CRITICAL)
Role: Flutter State Management Expert. Design predictable, testable state flows.
State Design Workflow
- Define Events: What happens? (UserTap, ApiSuccess). Use
@freezed. - Define States: What needs to show? (Initial, Loading, Data, Error).
- Implement BLoC: Map Events to States using
on<Event>. - Connect UI: Use
BlocBuilderfor rebuilds,BlocListenerfor side effects.
Implementation Guidelines
- States & Events: Use @freezed for union types (e.g.,
Initial,Loading,Success,Failurestates). - Error Handling: Emit
Failurestates for UI-critical errors. For silent/background events, either let exceptions propagate naturally to globalonErrorinterceptor (e.g., inAppBlocObserver), or catch and calladdError(e, st)without emitting error state. - Async Data: Use emit.forEach for streams or await with
emitcall. - Concurrency: Use transformer: restartable() from
bloc_concurrencyfor search/typeahead to debounce and cancel previous requests. - UI Connectivity: Use BlocBuilder for UI rebuilds (e.g., loading spinner, data list, error message) and BlocListener for side effects (navigation, snackbars).
- Testing: Use blocTest for ALL states and verify sequence of emitted states.
Verification Checklist (Mandatory)
- Initial State: Defined and tested?
- Test Coverage:
blocTestused for ALL states? - UI Logic: No complex calculation in
BlocBuilder? - Side Effects: Navigation/Snackbars in
BlocListener(NOT Builder)?
Anti-Patterns
- No .then(): Use
awaitoremit.forEach()to emit. - No BLoC-to-BLoC: Use
StreamSubscriptionorBlocListener, not direct refs. - No Logic in Builder: Move valid logic to BLoC.
- No BlocBuilder without buildWhen: Heavy subtrees must declare
buildWhenpredicate to prevent unnecessary rebuilds.
Verification
- Every BLoC has
blocTestcovering Initial → Loading → Success and Initial → Loading → Failure. - Side effects (navigation, snackbars) use
BlocListener, notBlocBuilder. - Heavy
BlocBuilderwidgets declarebuildWhen. -
flutter testpasses.
References
Event-handler correction
emit()is not a Future: Remove.then()from it, useawaitfor asynchronous work, and register the event with anon<Event>handler.
Canonical response anchors
When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:
- Remove
When not to use it
- →For generic widget-only work
- →For complex calculations in BlocBuilder
- →For direct BLoC-to-BLoC communication
Limitations
- →Does not support direct BLoC-to-BLoC communication
- →Complex calculations should not be in BlocBuilder
- →Side effects must use BlocListener, not BlocBuilder
How it compares
This skill provides a structured workflow for BLoC implementation, ensuring predictable and testable state flows, unlike ad-hoc state management approaches.
Compared to similar skills
flutter-bloc-state-management side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| flutter-bloc-state-management (this skill) | 0 | 3mo | No flags | Intermediate |
| flutter | 13 | 4mo | No flags | Intermediate |
| flutter-development | 1,555 | 5mo | No flags | Intermediate |
| flutter-expert | 73 | 4mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by HoangNguyen0403
View all by HoangNguyen0403 →You might also like
flutter
alinaqi
Flutter development with Riverpod state management, Freezed, go_router, and mocktail testing
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
flutter-expert
sickn33
Master Flutter development with Dart 3, advanced widgets, and multi-platform deployment. Handles state management, animations, testing, and performance optimization for mobile, web, desktop, and embedded platforms. Use PROACTIVELY for Flutter architecture, UI implementation, or cross-platform features.
mobile-developer
sickn33
Develop React Native, Flutter, or native mobile apps with modern architecture patterns. Masters cross-platform development, native integrations, offline sync, and app store optimization. Use PROACTIVELY for mobile features, cross-platform code, or app optimization.
stac-quickstart
StacDev
Help initialize and validate a Stac-enabled Flutter project and ship a first server-driven screen. Use when users ask to set up Stac CLI, run stac init/build/deploy, verify project prerequisites, or troubleshoot first-run setup and missing configuration files.
webf-native-plugins
openwebf
Install WebF native plugins to access platform capabilities like sharing, payment, camera, geolocation, and more. Use when building features that require native device APIs beyond standard web APIs.