bloc-cubit
하는 일
이 스킬은 Bloc과 Cubit 도구로 Flutter 앱의 데이터와 화면 변화를 정리하는 방법을 설명합니다. 명확하고 테스트하기 쉬운 상태 관리를 원하는 Flutter 개발자를 위한 스킬입니다.
사용하는 경우
- ✓Flutter 앱을 만들면서 바뀌는 화면 데이터를 관리해야 할 때.
- ✓기능에 Bloc과 Cubit 중 무엇을 쓸지 고르고 있을 때.
- ✓Flutter 상태 로직의 테스트를 설정하고 싶을 때.
스킬 링크
https://github.com/andrewyng/context-hub/blob/main/content/flutter/skills/state-management/bloc-cubit/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“Flutter 앱의 결제 화면에 Bloc 상태 관리를 설정하는 것을 도와줄 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 간단한 규칙을 줍니다. 직접적인 업데이트에는 Cubit을, 이벤트 중심의 단계에는 Bloc을 씁니다. 그다음 코드에서 따라야 할 설정과 구조를 보여 줍니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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()
자주 묻는 질문
Bloc과 Cubit은 어떻게 다른가요?
Cubit은 단순한 직접 업데이트를 처리하고, Bloc은 사용자 동작을 명시적인 이벤트로 모델링합니다.
Flutter 앱에 두 패키지가 모두 필요한가요?
보통은 필요하지 않습니다. flutter_bloc 패키지가 핵심 bloc 패키지를 함께 가져옵니다.
일반 Dart 프로젝트에도 쓸 수 있나요?
Dart 전용 프로젝트에는 Flutter 위젯 패키지 없이 bloc 패키지를 쓰라고 제안합니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 14k
- 순위
- #11269
- 라이선스
- MIT
- 업데이트
- 2026. 5. 31.
댓글
- …
이 저장소의 다른 스킬
get-api-docs
14k에이전트가 코드를 쓰기 전에, 오래된 기억 대신 서드파티 API와 라이브러리의 최신 문서를 가져오도록 돕습니다.
riverpod
14k에이전트가 Riverpod으로 Flutter 앱의 상태를 관리하도록 가르칩니다. 프로바이더, 비동기 데이터, 테스트를 다룹니다.
document-extraction
14k에이전트가 PDF, 이미지, 스프레드시트를 읽어 깨끗한 텍스트로 바꾸고, LandingAI ADE 서비스로 송장 합계 같은 항목을 뽑아내도록 돕습니다.
document-workflows
14k에이전트가 많은 문서를 일괄 처리하고, 검색용으로 준비하며, 결과를 데이터베이스에 넣는 파이프라인을 만들도록 돕습니다.
비슷한 스킬
android-clean-architecture
280k에이전트가 Android 프로젝트를 효율적으로 구성하도록 돕습니다. 유지보수와 새 기능 개발이 쉽도록 코드를 구조화합니다.
compose-multiplatform-patterns
280k에이전트가 KMP 프로젝트에서 Compose Multiplatform과 Jetpack Compose 패턴을 쓰도록 돕습니다. 상태, 내비게이션, 테마, 성능을 다룹니다.
dart-flutter-patterns
280kDart와 Flutter 앱용 코드를 작성하도록 에이전트를 돕습니다. 견고하고 관리하기 쉬운 앱을 만드는 현대적인 패턴을 씁니다.