/flutter-code-quality:state-managementfrom flutter-code-quality
Implements or reviews Flutter state management patterns including sealed state shapes, async lifecycle safety, narrow subscriptions, and state tests. Supports Bloc, Riverpod, Provider, Signals, and setState stacks.
Ships in flutter-code-quality. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Profile first. Read
.agents/flutter-profile.yamlin the project root, falling back to legacy.claude/flutter-profile.yaml, and take the stack fromstate. With no profile or field, inspect the affected feature and dependencies; do not introduce Bloc or Freezed by default. Read resolved versions before selecting APIs. Local setState can coexist with a feature state library. Then read the reference for that stack before writing code:
stateRead blocreferences/bloc.mdriverpodreferences/riverpod.mdprovider,signals,setstateNeither — apply the four rules below directly, using the translation table at the bottom Do not mix stacks. Adding a Cubit to a Riverpod codebase because a Cubit is what you know is the single most damaging thing an agent does to a state layer: it compiles, it works on the screen it was added to, and it leaves the project with two sources of truth that no reviewer asked for. Field list:
../architecture/references/flutter-profile.md, relative to this skill directory.
The four rules below hold under every stack. The references only differ in what the code for them looks like.
Use sealed alternatives for mutually exclusive states. Keep immutable data-class state for independent fields, forms, or retained data during refresh. Do not force a union onto a checkbox or rewrite a valid existing state model. Avoid impossible combinations in a class with many nullable fields. A nullable-everything state makes every widget check three fields to work out what to render, and the compiler stops helping.
Under models: freezed or dart_mappable, that is a sealed union. Under models: manual, it is a sealed class hierarchy written by hand — Dart 3 gives you exhaustive
switch on any sealed type, so the guarantee does not depend on codegen.
The point is the exhaustiveness. Adding a state member should produce a compile error everywhere it needs handling, rather than a silently missing case at runtime.
Every state update that follows an await needs a liveness guard in front of it. Without
one, navigating away mid-request throws. It is intermittent, it depends on network
timing, and it is very hard to reproduce from a bug report — which is exactly why an
agent will not add the guard unless told to.
Each stack spells the guard differently (isClosed, ref.mounted, mounted). All of
them need it. See your stack's reference.
A widget reading one field should rebuild when that field changes, and not otherwise. On a screen where a transaction list and a balance header read the same state, a whole-state subscription on the header rebuilds it on every list update.
Not fatal on its own, but it compounds, and it is free to avoid at authoring time and
tedious to retrofit. Every stack has a narrowing primitive — BlocSelector,
ref.watch(p.select(...)), context.select. Use it.
Side effects — navigation, snackbars, dialogs — are a separate subscription from rendering, never a branch inside a builder. A builder can run more than once for the same state; a snackbar that fires from inside one will eventually fire twice.
BuildContext in the state holderNavigation and snackbars are the widget's job. A Cubit or Notifier holding a
BuildContext has bound business logic to the widget tree and cannot be tested without
pumping one.
Test observable transitions for changed behavior: success and failure for fallible operations, disposal and out-of-order completion for overlapping async operations. A synchronous setter does not need an invented failure case. The failure path is the one that ships broken, because it is the one nobody clicks through manually.
Assert on the sequence of states, not just the final one. A method that reaches
loaded without passing through loading renders no spinner, and a test that only
checks the endpoint passes anyway.
| Rule | provider | signals | setstate |
|---|---|---|---|
| Liveness guard | ChangeNotifier has no mounted — set a _disposed flag in dispose() and return before notifyListeners() | disposal check before assigning | if (!mounted) return; in the State |
| Narrow subscription | context.select | fine-grained signal reads | n/a — keep the State small instead |
| Side effects | listener outside build | effect | after the await, not in build |
| Test entry point | construct the notifier directly | read the signal | testWidgets + pumpWidget |
setstate is legitimate for local state and state lifted to a suitable common ancestor.
Use the existing shared-state mechanism when lifetime or complexity warrants it; lifting
a checkbox value does not by itself justify a new dependency.
setState and notifyListeners rebuild regardless, which hides
the mistake until the code moves to a stack that compares. If a list changed in place,
produce a new list rather than mutating the existing one.build (context.read, ref.read). It does not
subscribe, so the UI goes stale in a way that looks like a caching bug.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
flutter-state, bloc, riverpod, provider, sealed-classes, async-lifecycle
npx claudepluginhub draz26648/flutter_craft_skills --plugin flutter-code-quality8 skills in this plugin
/a11y-and-rtlImplement or review Flutter semantics, keyboard access, text scaling, localization, and RTL behavior for affected user-facing controls./architecturePlace or refactor Flutter feature code using the project’s existing architecture and dependency boundaries. Use for structural changes, not every new file./codebase-conventionsFind and reuse existing Flutter components, styles, assets, and naming conventions before adding or changing UI code./flutter-adaptInspect a Flutter project and create or regenerate its agent profile and conventions when explicitly requested. Preserve existing user decisions./performanceDiagnose Flutter jank, expensive rebuilds, image memory, or long-list performance. Use for relevant list/image changes or measured performance issues./responsive-adaptiveImplement or debug Flutter layout across available widths, keyboard insets, orientations, and text scaling. Use for layout changes or overflow.Other plugins' skills for the same job