Agent skill

Bloc

by evanca in evanca/flutter-ai-rules

A skill your agent uses when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit…

MITAuto-check passedMobile

Install Bloc

skills CLI
$ npx skills add evanca/flutter-ai-rules --skill bloc -a claude-code

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

GitHub CLI
$ gh skill install evanca/flutter-ai-rules bloc --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/evanca/flutter-ai-rules.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/bloc .claude/skills/bloc && 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
GitHub stars
649
Token cost
~2.8k tokens
SKILL.md length
677 words
Files
1
Skills in repo
37
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit…

  • Works in 9 steps: Cubit vs Bloc → Naming Conventions → Modeling State → …
  • Creating a Cubit
  • SKILL.md covers When to Use, 1. Cubit vs Bloc, 2. Naming Conventions and 3. Modeling State, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Bloc is an agent skill from evanca/flutter-ai-rules. Use when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit and Bloc.

Its SKILL.md is about 2.8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering Cross-platform mobile apps. The repository describes itself as: Flutter AI Skills and Rules for Claude, Codex, Cursor, and Other AI-Powered IDEs. The licence is MIT.

When your agent uses it

  • Creating a Cubit
  • Modeling state with sealed classes
  • Wiring BlocBuilder/BlocListener/BlocProvider
  • Writing bloc tests

Example prompts

  • “/bloc”

Workflow steps

9 steps, taken from the step headings in SKILL.md.

  1. Cubit vs Bloc
  2. Naming Conventions
  3. Modeling State
  4. Cubit Implementation
  5. Bloc Implementation
  6. Architecture
  7. Flutter Bloc Widgets
  8. Testing
  9. Common Pitfalls

What it can do on your machine

Read from SKILL.md and the folder at commit 7b9cce2. 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 (its code samples are dart).

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

  • Network

    Links to these hosts (documentation or services it may open):

    • pub.dev
    • github.com

    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

Bloc loads about 2.8k tokens when it runs. Until then it costs about 48 tokens; SKILL.md has 677 words of instructions outside code blocks.

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

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 evanca/flutter-ai-rules at commit 7b9cce2, republished under its MIT licence (© evanca). 677 words, ~2,787 tokens.

Download SKILL.mdSave it as .claude/skills/bloc/SKILL.md (or your agent's skills folder).
name
bloc
description
Use when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit and Bloc.
license
MIT

Bloc Skill

Design, implement, and test state management using the bloc and flutter_bloc libraries.

When to Use

Use this skill when:

  • Creating a new Cubit or Bloc for a feature.
  • Modeling state (choosing between sealed classes and a single state class with status enum).
  • Wiring BlocBuilder, BlocListener, BlocConsumer, or BlocProvider in the widget tree.
  • Writing unit tests for a Cubit or Bloc.
  • Deciding between Cubit and Bloc.
  • Refactoring existing state management to follow bloc conventions.

1. Cubit vs Bloc

SituationUse
Simple state, no events neededCubit
Complex flows, event traceability neededBloc
Advanced event processing (debounce, throttle)Bloc with event transformers

Default to Cubit. Refactor to Bloc only when requirements grow.


2. Naming Conventions

Events (Bloc only)
  • Named in past tense: LoginButtonPressed, UserProfileLoaded.
  • Format: BlocSubject + optional noun + verb.
  • Initial load event: BlocSubjectStarted (e.g., AuthenticationStarted).
  • Base event class: BlocSubjectEvent.
States
  • Named as nouns (states are snapshots in time).
  • Base state class: BlocSubjectState.
  • Sealed subclasses: BlocSubject + Initial | InProgress | Success | Failure.
    • Example: LoginInitial, LoginInProgress, LoginSuccess, LoginFailure.
  • Single-class approach: BlocSubjectState + BlocSubjectStatus enum (initial, loading, success, failure).

3. Modeling State

When to use a sealed class with subclasses
  • States are well-defined and mutually exclusive.
  • Type-safe exhaustive switch is desired.
  • Subclass-specific properties exist.
dart
@immutable
sealed class LoginState extends Equatable {
  const LoginState();
}

final class LoginInitial extends LoginState {
  @override
  List<Object?> get props => [];
}

final class LoginInProgress extends LoginState {
  @override
  List<Object?> get props => [];
}

final class LoginSuccess extends LoginState {
  const LoginSuccess(this.user);
  final User user;
  @override
  List<Object?> get props => [user];
}

final class LoginFailure extends LoginState {
  const LoginFailure(this.message);
  final String message;
  @override
  List<Object?> get props => [message];
}

Handle all states exhaustively in the UI:

dart
switch (state) {
  case LoginInitial():  ...
  case LoginInProgress(): ...
  case LoginSuccess(:final user): ...
  case LoginFailure(:final message): ...
}
When to use a single class with a status enum
  • Many shared properties across states.
  • Simpler, more flexible; previous data must be retained after failure.
dart
enum LoginStatus { initial, loading, success, failure }

@immutable
class LoginState extends Equatable {
  const LoginState({
    this.status = LoginStatus.initial,
    this.user,
    this.errorMessage,
  });

  final LoginStatus status;
  final User? user;
  final String? errorMessage;

  LoginState copyWith({
    LoginStatus? status,
    User? user,
    String? errorMessage,
  }) {
    return LoginState(
      status: status ?? this.status,
      user: user ?? this.user,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }

  @override
  List<Object?> get props => [status, user, errorMessage];
}
State rules (both approaches)
  • Extend Equatable and pass all relevant fields to props.
  • Copy List/Map properties with List.of/Map.of inside props.
  • Annotate with @immutable.
  • Always emit a new instance; never reuse the same state object.
  • Duplicate states are ignored by bloc — ensure meaningful state changes.

4. Cubit Implementation

dart
class LoginCubit extends Cubit<LoginState> {
  LoginCubit(this._authRepository) : super(const LoginState());

  final AuthRepository _authRepository;

  Future<void> login(String email, String password) async {
    emit(state.copyWith(status: LoginStatus.loading));
    try {
      final user = await _authRepository.login(email, password);
      emit(state.copyWith(status: LoginStatus.success, user: user));
    } catch (e) {
      emit(state.copyWith(status: LoginStatus.failure, errorMessage: e.toString()));
    }
  }
}

Rules:

  • Only call emit inside the Cubit/Bloc.
  • Public methods return void or Future<void> only.
  • Keep business logic out of UI.
  • When overriding storage in a HydratedCubit, pass it as a named parameter: super(initialState, storage: storage).

5. Bloc Implementation

dart
sealed class LoginEvent {}
final class LoginSubmitted extends LoginEvent {
  LoginSubmitted({required this.email, required this.password});
  final String email;
  final String password;
}

class LoginBloc extends Bloc<LoginEvent, LoginState> {
  LoginBloc(this._authRepository) : super(LoginInitial()) {
    on<LoginSubmitted>(_onLoginSubmitted);
  }

  final AuthRepository _authRepository;

  Future<void> _onLoginSubmitted(
    LoginSubmitted event,
    Emitter<LoginState> emit,
  ) async {
    emit(LoginInProgress());
    try {
      final user = await _authRepository.login(event.email, event.password);
      emit(LoginSuccess(user));
    } catch (e) {
      emit(LoginFailure(e.toString()));
    }
  }
}

Rules:

  • Trigger state changes via bloc.add(Event()), not custom public methods.
  • Keep event handler methods private (_onEventName).
  • Internal/repository events must be private and may use custom transformers.

6. Architecture

Three layers — each must stay in its own boundary:

Presentation  →  Business Logic (Cubit/Bloc)  →  Data (Repository → DataProvider)
  • Data Layer: Repositories wrap data providers. Providers perform raw CRUD (HTTP, DB). Repositories expose clean domain objects.
  • Business Logic Layer: Cubits/Blocs receive repository data and emit states. Inject repositories via constructor.
  • Presentation Layer: Renders UI based on state. Handles user input by calling cubit methods or adding bloc events.

Rules:

  • Blocs must not access data providers directly — only via repositories.
  • No direct bloc-to-bloc communication. Use BlocListener in the UI to bridge blocs.
  • For shared data, inject the same repository into multiple blocs.
  • Initialize BlocObserver in main.dart.

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

7. Flutter Bloc Widgets

WidgetUse
BlocProviderProvide a bloc to a subtree
MultiBlocProviderProvide multiple blocs without nesting
BlocBuilderRebuild UI on state change
BlocListenerSide effects only (navigation, dialogs, snackbars)
MultiBlocListenerListen to multiple blocs without nesting
BlocConsumerRebuild UI + side effects together
BlocSelectorRebuild only when a selected slice of state changes
RepositoryProviderProvide a repository to the widget tree
MultiRepositoryProviderProvide multiple repositories without nesting
dart
BlocProvider(
  create: (context) => LoginCubit(context.read<AuthRepository>()),
  child: LoginView(),
);

BlocBuilder<LoginCubit, LoginState>(
  builder: (context, state) {
    return switch (state.status) {
      LoginStatus.loading => const CircularProgressIndicator(),
      LoginStatus.success => const HomeView(),
      LoginStatus.failure => Text(state.errorMessage ?? 'Error'),
      LoginStatus.initial => const LoginForm(),
    };
  },
);

BlocListener<LoginCubit, LoginState>(
  listener: (context, state) {
    if (state.status == LoginStatus.failure) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text(state.errorMessage ?? 'Login failed')),
      );
    }
  },
  child: LoginForm(),
);

Rules:

  • Use context.read<T>() in callbacks (not in build).
  • Use context.watch<T>() in build only when necessary; prefer BlocBuilder.
  • Never call context.watch or context.select at the root of build — scope with Builder.
  • Handle all possible states in the UI (initial, loading, success, failure).

8. Testing

Use bloc_test package. Mock repositories with mocktail.

dart
import 'package:bloc_test/bloc_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class MockAuthRepository extends Mock implements AuthRepository {}

void main() {
  group('LoginCubit', () {
    late AuthRepository authRepository;
    late LoginCubit loginCubit;

    setUp(() {
      authRepository = MockAuthRepository();
      loginCubit = LoginCubit(authRepository);
    });

    tearDown(() => loginCubit.close());

    test('initial state should be LoginState with status initial', () {
      expect(loginCubit.state, const LoginState());
    });

    blocTest<LoginCubit, LoginState>(
      'should emit [loading, success] when login succeeds',
      build: () {
        when(() => authRepository.login(any(), any()))
            .thenAnswer((_) async => fakeUser);
        return loginCubit;
      },
      act: (cubit) => cubit.login('email@test.com', 'password'),
      expect: () => [
        const LoginState(status: LoginStatus.loading),
        LoginState(status: LoginStatus.success, user: fakeUser),
      ],
    );

    blocTest<LoginCubit, LoginState>(
      'should emit [loading, failure] when login throws',
      build: () {
        when(() => authRepository.login(any(), any()))
            .thenThrow(Exception('error'));
        return loginCubit;
      },
      act: (cubit) => cubit.login('email@test.com', 'wrong'),
      expect: () => [
        const LoginState(status: LoginStatus.loading),
        isA<LoginState>().having((s) => s.status, 'status', LoginStatus.failure),
      ],
    );
  });
}

Rules:

  • Always call tearDown(() => cubit.close()).
  • Use blocTest for state emission assertions.
  • Use group() named after the class under test.
  • Name test cases with "should" to describe expected behavior.
  • Register fallback values for custom types: registerFallbackValue(MyEvent()).

9. Common Pitfalls

PitfallFix
Emitting the same state instance twiceAlways create a new state object; bloc ignores duplicate emissions via ==.
Calling context.watch inside callbacksUse context.read in callbacks; watch is only valid inside build.
Forgetting Equatable propsAdd every field to props; missing fields cause silent state update bugs.
Mutable state fieldsKeep state @immutable; use copyWith or new sealed subclass instances.
Business logic in widgetsMove all logic into the Cubit/Bloc; widgets only dispatch events or call methods.
dart
// BAD — mutating state in-place
state.items.add(newItem);
emit(state);

// GOOD — emit a new state with copied list
emit(state.copyWith(items: [...state.items, newItem]));

References

© evanca, 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 skills/bloc of evanca/flutter-ai-rules.

Open the folder on GitHubat commit 7b9cce2

Compare with similar skills

Bloc 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.

Bloc compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Bloc this skillevanca/flutter-ai-rules649—~2.8kAutomated safety check: PassMIT
React Native Best Practicesvercel-labs/openreview1.7k17 repos~1.1kAutomated safety check: PassMIT
Compose Multiplatform Patternsmonta-app/ocpp-emulator1805 repos~2kAutomated safety check: PassApache-2.0
Creating Reanimated Animationsgluestack/gluestack-ui5.3k—~2.4kAutomated safety check: PassNone
Uni-app Components and APIsfeige996/unibest2.3k—~1.6kAutomated safety check: PassMIT
Add Flutter Docusaurus Localematthiasn/lotti1.2k—~1.2kAutomated safety check: PassGPL-3.0

Similar skills

  • React Native Best Practices

    vercel-labs/openreview

    Official

    A prioritized rule set for React Native and Expo apps covering list performance, animation, navigation, UI patterns, state, rendering, monorepos and configuration.

    1.7k GitHub starsUsed in 17 repos~1.1k tokens
    MobileAuto-check passed
  • Compose Multiplatform Patterns

    monta-app/ocpp-emulator

    Compose Multiplatform and Jetpack Compose patterns for KMP projects — state management, navigation, theming, performance, and platform-specific UI.

    180 GitHub starsUsed in 5 repos~2k tokens
    MobileAuto-check passed
  • Creating Reanimated Animations

    gluestack/gluestack-ui

    Generate React Native Reanimated animation code for React Native apps.

    5.3k GitHub stars~2.4k tokensUpdated 1 mo ago
    MobileAuto-check passed
  • Gives per-component and per-API examples, reference specs and compatibility notes for building cross-platform uni-app apps, mirroring the official documentation.

    2.3k GitHub stars~1.6k tokensUpdated 23 days ago
    MobileAuto-check passed
  • Add, complete, or audit a locale across a Flutter application's ARB catalogs and a localized Docusaurus manual, including generated localization code, locale selectors, native platform declarations…

    1.2k GitHub stars~1.2k tokensUpdated yesterday
    MobileAuto-check passed
  • Jetpack Compose Expert

    aldefy/compose-skill

    Guides Jetpack Compose and Compose Multiplatform work across Android, Desktop, iOS and web, plus Android TV, Material 3 motion, paging, navigation and design-to-code.

    596 GitHub stars~4.8k tokensUpdated 2 mo ago
    MobileAuto-check passed

More from evanca/flutter-ai-rules

All 37 skills in this repo
  • Code Review

    evanca/flutter-ai-rules

    A skill your agent uses when asked to review a PR, MR, branch, or diff, audit changed files, or check code quality.

    649 GitHub stars~2.4k tokensUpdated 24 days ago
    Auto-check passed
  • Developing Genkit Dart

    evanca/flutter-ai-rules

    A skill your agent uses when building AI agents in Dart, implementing Genkit flows or tools, integrating LLMs into Dart or Flutter applications, or using Genkit Dart plugins.

    649 GitHub stars~961 tokensUpdated 24 days ago
    Auto-check passed
  • Generate Images With Firebase AI

    evanca/flutter-ai-rules

    A skill your agent uses when generating or editing images from Flutter/Dart with Firebase AI Logic and a Gemini image model (Nano Banana), making the first call work, choosing Gemini Developer API…

    649 GitHub stars~2.3k tokensUpdated 24 days ago
    Auto-check passed
  • Flutter Use Column Row First

    evanca/flutter-ai-rules

    A skill your agent uses when building any Flutter screen or component to choose responsive Row, Column, Expanded, Flexible, and Spacer layouts before fixed-size or coordinate-based alternatives.

    649 GitHub stars~1.3k tokensUpdated 24 days ago
    Auto-check passed
  • Architecture Feature First

    evanca/flutter-ai-rules

    A skill your agent uses when creating a feature, designing folder structure, adding repositories/services/view models, wiring dependency injection, or deciding which layer owns logic.

    649 GitHub stars~1.9k tokensUpdated 24 days ago
    Auto-check passed
  • Dart 3 Updates

    evanca/flutter-ai-rules

    A skill your agent uses when writing switch statements, refactoring if-else chains, creating data classes, choosing records vs classes, destructuring values, or modernizing pre-Dart-3 code.

    649 GitHub stars~2k tokensUpdated 24 days ago
    Auto-check passed

Categories

Questions about Bloc

What does Bloc do?

A skill your agent uses when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit…. Bloc is an agent skill from evanca/flutter-ai-rules. Use when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit and Bloc.

When should I use Bloc?

Bloc fits situations like: creating a Cubit; modeling state with sealed classes; wiring BlocBuilder/BlocListener/BlocProvider; writing bloc tests.

How do I install Bloc in Claude Code?

Run `npx skills add evanca/flutter-ai-rules --skill bloc -a claude-code`. Or copy the skill folder (skills/bloc in evanca/flutter-ai-rules) into .claude/skills/bloc in your project. Claude Code loads it when a task matches its description.

How do I install Bloc in Codex?

Run `npx skills add evanca/flutter-ai-rules --skill bloc -a codex`. Or copy the skill folder (skills/bloc in evanca/flutter-ai-rules) into .agents/skills/bloc in your project. Codex loads it when a task matches its description.

Can I use Bloc 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 evanca/flutter-ai-rules --skill bloc -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, .gemini/skills/bloc, .github/skills/bloc and .opencode/skills/bloc in your project.

What does Bloc need to run?

SKILL.md names no scripts, command-line tools or credentials: Bloc is instructions for the agent only.

Does Bloc access the network?

SKILL.md names 2 domains. As links in the text: pub.dev and github.com. This is read from the text; nothing was executed.

Is Bloc 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 Bloc use?

Bloc is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Bloc use?

About 2.8k tokens (SKILL.md is roughly 11k 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 Bloc?

Skills that share tags, products or a category with Bloc: React Native Best Practices (vercel-labs/openreview, 1.7k stars), Compose Multiplatform Patterns (monta-app/ocpp-emulator, 180 stars), Creating Reanimated Animations (gluestack/gluestack-ui, 5.3k stars) and Uni-app Components and APIs (feige996/unibest, 2.3k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Bloc?

evanca (a GitHub user) maintains it in evanca/flutter-ai-rules, which has 649 GitHub stars. The repository holds 37 skills in this directory. The repository was last updated on September 14, 2026.

Source: evanca/flutter-ai-rules on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.