Agent skill

Flutter Bloc and Cubit

by andrewyng in andrewyng/context-hub

Helps choose between Bloc and Cubit in Flutter and sets defaults for packages, lifecycle, widget binding and tests.

MITAuto-check passedMobile

Install Flutter Bloc and Cubit

skills CLI
$ npx skills add andrewyng/context-hub --skill bloc-cubit -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install andrewyng/context-hub bloc-cubit --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/andrewyng/context-hub.git skills-src && mkdir -p .claude/skills && cp -r skills-src/content/flutter/skills/state-management/bloc-cubit .claude/skills/bloc-cubit && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
bloc-cubit
GitHub stars
14k
Token cost
~998 tokens
SKILL.md length
509 words
Files
1
Skills in repo
8
Repo updated
First seen
Licence
MIT

At a glance

Helps choose between Bloc and Cubit in Flutter and sets defaults for packages, lifecycle, widget binding and tests.

  • Choosing between Bloc and Cubit for a Flutter feature
  • SKILL.md covers Core Rule, Decision Guide, Required Project Setup and Implementation Pattern, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Adding flutter_bloc to a Flutter app

What it does

The core rule is that Cubit suits simple, direct state updates, such as counters, toggles, filters, form flags and theme mode, while Bloc suits event-driven flows with explicit transitions, such as auth, pagination, checkout, sync and multi-step workflows. Dart-only projects add the bloc package, and Flutter apps add flutter_bloc, which brings bloc along, for BlocProvider, BlocBuilder and BlocListener.

The suggested structure keeps I/O in a repository or service, state and orchestration in the bloc or cubit, and only action dispatching and rendering in the UI, with immutable state, explicit events for Bloc and one bloc or cubit per feature responsibility. Blocs you create yourself must be closed with close(), while instances owned by BlocProvider must not be. BlocBuilder rebuilds, BlocListener reacts without rebuilding, BlocConsumer is for both, and buildWhen, listenWhen and BlocSelector narrow updates.

Cubits are tested by calling methods and asserting emitted states, and Blocs by adding events and asserting the transition sequence. The excerpt is cut off after the first testing rules.

When your agent uses it

  • Choosing between Bloc and Cubit for a Flutter feature
  • Adding flutter_bloc to a Flutter app
  • Deciding who is responsible for closing a bloc or cubit
  • Writing tests for a Cubit or a Bloc

Example prompts

  • “Should the theme toggle be a Cubit or a Bloc?”
  • “Build the login flow with Bloc: events for submit and logout, states for loading, success and failure.”
  • “Write tests for the counter Cubit that assert the emitted states.”

Requirements

  • A Flutter or Dart project using the bloc or flutter_bloc package

What it can do on your machine

Read from SKILL.md and the folder at commit 67dcbeb. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Flutter Bloc and Cubit loads about 998 tokens when it runs. Until then it costs about 47 tokens; SKILL.md has 509 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~47
When it runs · the whole SKILL.md, loaded when a task matches
~998

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from andrewyng/context-hub at commit 67dcbeb, republished under its MIT licence (© andrewyng). 509 words, ~998 tokens.

Download SKILL.mdSave it as .claude/skills/bloc-cubit/SKILL.md (or your agent's skills folder).
name
bloc-cubit
description
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.
metadata.revision
1
metadata.updated-on
2026-04-04
metadata.source
official
metadata.tags
flutter,dart,bloc,cubit,flutter_bloc,state-management,testing,architecture

Flutter Bloc/Cubit State Management

Use this skill when building Flutter state management with bloc and flutter_bloc.

Core Rule

  • Use Cubit for simple, direct state updates.
  • Use Bloc for event-driven flows, transitions, and replayable business logic.
  • Use bloc in Dart-only projects.
  • Use flutter_bloc in Flutter apps when you need widgets like BlocProvider, BlocBuilder, or BlocListener.
  • If you install flutter_bloc, you do not need to add bloc separately in a Flutter app because flutter_bloc depends 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_bloc unless Flutter widgets are needed

For Flutter UI code:

  • add flutter_bloc
  • let it bring bloc transitively
  • use BlocProvider at the feature boundary
  • use BlocBuilder for rebuilds and BlocListener for 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 BlocProvider or MultiBlocProvider to let Flutter manage disposal.
  • If you create a bloc/cubit with new or 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.

Show full SKILL.md (189 more words)Show less

Testing Rules

  • Test Cubit by calling methods and asserting emitted states.
  • Test Bloc by 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 Bloc for trivial local state.
  • Do not add both bloc and flutter_bloc in a Flutter app when only flutter_bloc is 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 bloc or flutter_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 package
  • flutter_bloc = Flutter UI integration package
  • Cubit = method-based updates
  • Bloc = event-based transitions
  • manual creation = manual close()
  • provider-owned instance = no manual close()

© andrewyng, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in content/flutter/skills/state-management/bloc-cubit of andrewyng/context-hub.

Open the folder on GitHubat commit 67dcbeb

Compare with similar skills

Flutter Bloc and Cubit next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Flutter Bloc and Cubit compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Flutter Bloc and Cubit this skillandrewyng/context-hub14k—~998Automated safety check: PassMIT
BlocVeryGoodOpenSource/vgv-ai-flutter-plugin170—~2kAutomated safety check: PassMIT
Flutter Dart Code Reviewaffaan-m/ECC276k2 repos~5.8kAutomated safety check: NotesMIT
Signals for Flutterrodydavis/signals.dart819—~1.9kAutomated safety check: PassApache-2.0
Flutter ExpertFNOSP/FlyNarwhal5092 repos~758Automated safety check: PassMIT
Signals Core Advanced Primitivesrodydavis/signals.dart819—~1.7kAutomated safety check: PassApache-2.0

Similar skills

  • Bloc

    VeryGoodOpenSource/vgv-ai-flutter-plugin

    Best practices for Bloc state management in Flutter/Dart, covering Cubit versus Bloc, event and state naming, sealed classes with Equatable, the Page/View split with BlocProvider, BlocBuilder…

    170 GitHub stars~2k tokensUpdated 4 days ago
    MobileAuto-check passed
  • Library-agnostic Flutter/Dart code review checklist covering widget best practices, state management patterns (BLoC, Riverpod, Provider, GetX, MobX, Signals), Dart idioms, performance…

    276k GitHub starsUsed in 2 repos~5.8k tokens
    MobileAuto-check: notes
  • Signals for Flutter

    rodydavis/signals.dart

    Reference for the signals_flutter package: reactive signals, computed values, effects, async signals and collection signals bound to Flutter widgets.

    819 GitHub stars~1.9k tokensUpdated 27 days ago
    MobileAuto-check passed
  • Flutter Expert

    FNOSP/FlyNarwhal

    A skill your agent uses when building cross-platform applications with Flutter 3+ and Dart.

    509 GitHub starsUsed in 2 repos~758 tokens
    MobileAuto-check passed
  • Signals Core Advanced Primitives

    rodydavis/signals.dart

    Reference for the advanced parts of Dart's signals_core: reactive primitives, async signals, reactive collections and utility types, with a linked page for each.

    819 GitHub stars~1.7k tokensUpdated 27 days ago
    DevelopmentAuto-check passed
  • Mobile Development

    rohitg00/awesome-claude-code-toolkit

    Mobile development patterns for React Native and Flutter including navigation, state management, and responsive design

    2.7k GitHub stars~1.5k tokensUpdated 5 mo ago
    MobileAuto-check passed

More from andrewyng/context-hub

All 8 skills in this repo
  • Get API Docs with chub

    andrewyng/context-hub

    Fetches current documentation for third-party APIs and SDKs with the chub CLI before the agent writes code against them, instead of relying on remembered API shapes.

    14k GitHub starsUsed in 1 repo~775 tokens
    Auto-check passed
  • Tavily Search API Integration

    andrewyng/context-hub

    Guides building Tavily integrations for web search, URL extraction, site crawling and AI-assisted research in Python or JavaScript agent and RAG projects.

    14k GitHub stars~1.1k tokensUpdated 4 mo ago
    Auto-check passed
  • Sequences parts-mcp tool calls for finding, pricing and checking availability of electronic components, including BOM processing and datasheet navigation.

    14k GitHub stars~1.8k tokensUpdated 4 mo ago
    Auto-check passed
  • Olakai Monitoring Integration

    andrewyng/context-hub

    Adds Olakai monitoring to an existing LLM application with minimal code changes, then configures custom KPIs so the dashboard tracks business outcomes instead of just token counts.

    14k GitHub stars~4.5k tokensUpdated 4 mo ago
    Auto-check passed
  • Playwright Login Flows

    andrewyng/context-hub

    Collects reusable Playwright patterns for logging in during end-to-end tests: password forms, OAuth redirects, saved browser state and TOTP two-factor codes.

    14k GitHub stars~715 tokensUpdated 4 mo ago
    Auto-check passed
  • Olakai Agent Project Setup

    andrewyng/context-hub

    Builds a new AI agent with Olakai monitoring from the start: CLI login, SDK integration, per-agent KPI configuration and an end-to-end check that data flows.

    14k GitHub stars~5k tokensUpdated 4 mo ago
    Auto-check passed

Works with

Questions about Flutter Bloc and Cubit

What does Flutter Bloc and Cubit do?

Helps choose between Bloc and Cubit in Flutter and sets defaults for packages, lifecycle, widget binding and tests. The core rule is that Cubit suits simple, direct state updates, such as counters, toggles, filters, form flags and theme mode, while Bloc suits event-driven flows with explicit transitions, such as auth, pagination, checkout, sync and multi-step workflows. Dart-only projects add the bloc package, and Flutter apps add flutter_bloc, which brings bloc along, for BlocProvider, BlocBuilder and BlocListener.

When should I use Flutter Bloc and Cubit?

Flutter Bloc and Cubit fits situations like: choosing between Bloc and Cubit for a Flutter feature; adding flutter_bloc to a Flutter app; deciding who is responsible for closing a bloc or cubit; writing tests for a Cubit or a Bloc.

How do I install Flutter Bloc and Cubit in Claude Code?

Run `npx skills add andrewyng/context-hub --skill bloc-cubit -a claude-code`. Or copy the skill folder (content/flutter/skills/state-management/bloc-cubit in andrewyng/context-hub) into .claude/skills/bloc-cubit in your project. Claude Code loads it when a task matches its description.

How do I install Flutter Bloc and Cubit in Codex?

Run `npx skills add andrewyng/context-hub --skill bloc-cubit -a codex`. Or copy the skill folder (content/flutter/skills/state-management/bloc-cubit in andrewyng/context-hub) into .agents/skills/bloc-cubit in your project. Codex loads it when a task matches its description.

Can I use Flutter Bloc and Cubit in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add andrewyng/context-hub --skill bloc-cubit -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/bloc-cubit, .gemini/skills/bloc-cubit, .github/skills/bloc-cubit and .opencode/skills/bloc-cubit in your project.

What does Flutter Bloc and Cubit need to run?

SKILL.md names no scripts, command-line tools or credentials: Flutter Bloc and Cubit is instructions for the agent only. Our summary lists: A Flutter or Dart project using the bloc or flutter_bloc package.

Does Flutter Bloc and Cubit access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Flutter Bloc and Cubit safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Flutter Bloc and Cubit use?

Flutter Bloc and Cubit is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Flutter Bloc and Cubit use?

About 998 tokens (SKILL.md is roughly 4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Flutter Bloc and Cubit?

Skills that share tags, products or a category with Flutter Bloc and Cubit: Bloc (VeryGoodOpenSource/vgv-ai-flutter-plugin, 170 stars), Flutter Dart Code Review (affaan-m/ECC, 276k stars), Signals for Flutter (rodydavis/signals.dart, 819 stars) and Flutter Expert (FNOSP/FlyNarwhal, 509 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Flutter Bloc and Cubit?

andrewyng (a GitHub user) maintains it in andrewyng/context-hub, which has 13,973 GitHub stars. The repository holds 8 skills in this directory. The repository was last updated on May 31, 2026.

Source: andrewyng/context-hub on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.