bloc-cubit
Qué hace
Esta skill explica cómo organizar los datos y los cambios de pantalla en apps de Flutter usando las herramientas Bloc y Cubit. Está pensada para desarrolladores que crean apps en Flutter y quieren un manejo del estado claro y comprobable.
Cuándo usarla
- ✓Cuando creas una app en Flutter y necesitas gestionar datos de pantalla que cambian.
- ✓Cuando eliges entre Bloc y Cubit para una función.
- ✓Cuando quieres configurar pruebas para la lógica de estado de Flutter.
Link de la skill
https://github.com/andrewyng/context-hub/blob/main/content/flutter/skills/state-management/bloc-cubit/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Quiero configurar la gestión de estado con Bloc para la pantalla de pago de mi app en Flutter.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill ofrece una regla sencilla: usa Cubit para actualizaciones directas y Bloc para pasos dirigidos por eventos. Después muestra la configuración y la estructura que hay que seguir en el código.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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()
Preguntas frecuentes
¿Cuál es la diferencia entre Bloc y Cubit?
Cubit gestiona actualizaciones directas y sencillas, mientras que Bloc modela las acciones del usuario como eventos explícitos.
¿Necesito los dos paquetes en una app de Flutter?
Normalmente no. El paquete flutter_bloc incluye por sí solo el paquete bloc básico.
¿Sirve para proyectos normales de Dart?
En proyectos solo de Dart, la skill sugiere el paquete bloc sin el paquete de widgets de Flutter.
Detalles
Descripción original del autor
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
Popularidad
- Estrellas en GitHub
- 14 mil
- Posición en el ranking
- #11269
- Licencia
- MIT
- Actualizada
- 31/5/2026
Comentarios
- …
Más skills de este repositorio
get-api-docs
14 milAyuda a tu agente a obtener documentación actualizada de APIs y bibliotecas de terceros antes de escribir código, en lugar de confiar en la memoria antigua.
riverpod
14 milEnseña a tu agente a gestionar el estado de una app en Flutter con Riverpod, cubriendo providers, datos asíncronos y pruebas, con valores predeterminados sensatos para cada caso.
document-extraction
14 milAyuda a tu agente a leer PDFs, imágenes y hojas de cálculo, convertirlos en texto limpio y extraer campos como los totales de una factura usando el servicio ADE de LandingAI.
document-workflows
14 milAyuda a tu agente a crear flujos repetibles que procesan muchos documentos a la vez, los preparan para herramientas de búsqueda y cargan los resultados en una base de datos.
Skills parecidas
android-clean-architecture
280 milHace que tu agente organice proyectos de Android de forma eficiente. Estructura el código para facilitar el mantenimiento y el desarrollo de nuevas funciones.
compose-multiplatform-patterns
280 milAyuda a tu agente a usar patrones de Compose Multiplatform y Jetpack Compose en proyectos KMP, incluyendo estado, navegación, temas y rendimiento.
dart-flutter-patterns
280 milHace que tu agente escriba código para apps de Dart y Flutter. Usa patrones modernos para crear apps robustas y fáciles de mantener.