/utopia-hooks:utopia-hooksfrom Utopia Hooks
Flutter state management with utopia_hooks. Applies when writing Flutter screens, adding shared app state, handling async operations, building paginated / infinite-scroll lists, composing tab / bottom-nav / multi-page shells, sequencing app startup and bootstrap, handling global and retryable errors, building form fields (useFieldState, TextEditingControllerWrapper), unit-testing hook states (SimpleHookContext), injecting services, or migrating away from StatefulWidget. Covers the Screen/State/View pattern, the hook catalog, global state registration, async / paginated / submit hooks, navigation conventions, and dependency injection. Does NOT cover BLoC/Cubit migration (use utopia-hooks-migrate-bloc) or admin/CMS table screens (use utopia-cms).
Ships in Utopia Hooks. 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.
Holistic state management for Flutter using hooks. Every screen follows the
Screen → State → View tripartite pattern. Shared app state lives in
StateClass + hook + _providers. All logic belongs in hooks - never in widgets.
Crazy* widgets in examples (CrazyButton, CrazyTextField, …) are stand-ins for your
app's design system - substitute your own components or Material equivalents.
Reference these guidelines when:
setState patternsStatefulWidget (for BLoC/Cubit migration, use the dedicated utopia-hooks-migrate-bloc plugin)Full documentation with code examples in references/. Impact ratings: CRITICAL (always apply), HIGH (significant correctness/quality gain), MEDIUM (worthwhile improvement).
| Priority | File | Impact | Description |
|---|---|---|---|
| 1 | screen-state-view.md | CRITICAL | 3-file screen pattern: Screen, State class + hook, View; lightweight tier; dialogs with results |
| 2 | hooks-reference.md | CRITICAL | Full hook catalog: useState, useMemoized, useEffect, useProvided, useInjected, useIf, useMap, computed states, wrappers |
| 3 | global-state.md | CRITICAL | App-wide state: StateClass, HasInitialized, MutableValue, _providers registration, global-state idioms |
| 4 | async-patterns.md | HIGH | useSubmitState, useAutoComputedState, useMemoizedStream, usePersistedState, retryable errors, lifecycle effects, sticky values |
| 5 | paginated.md | HIGH | usePaginatedComputedState + PaginatedComputedStateWrapper: cursor/page/token schemes, loadMore, refresh, debounce, dedup, optimistic overlay |
| 6 | app-bootstrap.md | HIGH | Ordered _providers, HasInitialized chains, combined initialization state, splash gating, SDK init races, retryable bootstrap |
| 7 | error-handling.md | HIGH | Where let-it-crash errors land: app-root catcher (zone + FlutterError.onError), error stream + root dialog, Retryable retry, typed errors to field errors |
| 8 | navigation.md | HIGH | Route declaration conventions, typed args, reactive navigation effects, status-driven redirects, screen-as-sheet/dialog with typed results, one-shot event fields |
| 9 | multi-page-shell.md | HIGH | Shell-with-N-pages composition: shell is Screen/State/View, each inner page is Screen/State/View; enum/index, IndexedStack/PageView/TabBarView, local/global index |
| 10 | complex-state-examples.md | HIGH | Five anonymised reference shapes for complex state (pipeline / dashboard / parent-owned list / per-item widget-level / multi-step flow) |
| 11 | composable-hooks.md | HIGH | Widget-level hooks, composed hook state, screen hook decomposition, per-item state archetypes |
| 12 | flutter-conventions.md | HIGH | IList/IMap/ISet, it lambdas, strict analyzer, widget extraction, spacing, generated code, TextEditingController |
| 13 | testing.md | HIGH | Unit testing hooks with SimpleHookContext and SimpleHookProviderContainer - no widget tree needed; mocking injected services |
| 14 | di-services.md | MEDIUM | utopia_injector, useInjected, DI bridge hooks, service types, get_it fallback |
| 15 | utopia-cli.md | MEDIUM | utopia_cli agent surfaces: project inspection (describe), screen scaffolding (add screen --json), repo audit (doctor), hooks analyze variants, MCP server setup |
A pointer-paragraph for the four most-common entry points. For everything else, jump straight to the guidelines table above. Do not extrapolate from the summaries.
Every screen = 3 files: feature_screen.dart (HookWidget, pure wiring - builds nav callbacks from BuildContext, calls exactly one useXScreenState(...)), state/feature_screen_state.dart (immutable State class + hook with all logic), view/feature_screen_view.dart (StatelessWidget, View receives only state).
State class (often extends HasInitialized) + useXState() hook + entry in _providers map at app root. Consume with useProvided<XState>() inside any state hook. ValueProvider for static/already-computed values.
useAutoComputedState - auto-fetches, re-runs on keys change, shouldCompute gates prerequisitesuseSubmitState - user-triggered; tracks in-flight runs but does NOT block duplicate calls (the three guards are in async-patterns.md); let errors crash by defaultuseMemoizedStream - subscribes continuously, re-subscribes on keys changeusePersistedState - one MutableValue-shaped object per setting: .value reads, .value = x writes optimistically then persists (isSynchronized flags an in-flight write). The shape for settings/preferences surfaces - never split them into a read snapshot plus setter wrappersAny cursor-based list - feed, search results, chat history - uses usePaginatedComputedState + PaginatedComputedStateWrapper (scroll listener + pull-to-refresh). Never hand-roll useState<List<T>> + hasMore + cursor. Cursor is opaque (int for offset/page, String? for token). For confirmed optimistic edits/deletes, override the buffer with updateValues(items, {cursor}) / updateAt / deleteAt (decrement the cursor on offset/page deletes to avoid skipping); reserve a render-time override layer for transient/uncommitted UI state.
All paths below are relative to the skill root (the directory containing this SKILL.md).
From elsewhere, use the absolute form, e.g.
grep -rl "useSubmitState" /path/to/plugins/utopia-hooks/skills/utopia-hooks/references/.
# Async / data-loading hooks
grep -rl "useAutoComputedState" references/
grep -rl "useComputedState" references/
grep -rl "useSubmitState" references/
grep -rl "usePersistedState" references/
grep -rl "useMemoizedStream" references/
grep -rl "usePaginatedComputedState\|PaginatedComputedStateWrapper" references/
grep -rl "useDebounced" references/
# Core / lifecycle hooks
grep -rl "useMemoized" references/
grep -rl "useEffect" references/
grep -rl "useMap" references/
grep -rl "useIf" references/
grep -rl "useKeyed" references/
# Form / input hooks
grep -rl "useFieldState" references/
grep -rl "useFocusNode" references/
# Global state + DI types
grep -rl "HasInitialized" references/
grep -rl "MutableValue" references/
grep -rl "useProvided" references/
grep -rl "useInjected" references/
# Bootstrap / errors / navigation
grep -rl "Retryable" references/
grep -rl "HasInitialized.all" references/
grep -rl "useCombinedInitializationState" references/
grep -rl "buildRoute" references/
The canonical utopia_hooks convention analyzer lives in utopia_cli, not in this skill's
shell scripts - Claude, Codex, CI, and pre-commit all run the same rules. The plugin's
PostToolUse hook validates every Dart edit via utopia hooks analyze --hook-json; for
manual / batch / changed-file / CI variants, repo-wide utopia doctor audits, project
inspection (utopia describe), scaffolding (utopia add screen --json), and the
utopia mcp server, see utopia-cli.md.
When analyzing, testing, formatting, or fixing Dart code, prefer Dart MCP tools over their bash equivalents - they return structured results and pick up the active SDK (including fvm-pinned versions) automatically.
| Task | Dart MCP (preferred) | Bash fallback |
|---|---|---|
| Static analysis | analyze_files | dart analyze / flutter analyze |
| Run tests | run_tests | dart test / flutter test |
| Format code | dart_format | dart format |
| Apply dart fixes | dart_fix | dart fix --apply |
| Pub operations | pub | dart pub get / flutter pub add |
Use bash only in shell-only contexts (CI, pre-commit hooks) or when no MCP equivalent
exists (build_runner, melos, flutter build, ffigen). Setup: if claude mcp list
doesn't show dart, run claude mcp add -s user dart -- fvm dart mcp-server
(drop fvm if the repo doesn't use it).
| Problem | Start With |
|---|---|
| Adding a new screen | utopia-cli.md (utopia add screen --json) → screen-state-view.md |
| What screens/routes/global states already exist in this project? | utopia-cli.md (utopia describe) |
| Repo-wide convention audit / CI gate | utopia-cli.md (utopia doctor) |
| Logic is leaking into the View | screen-state-view.md |
| Widget imports in a State class | screen-state-view.md |
| App-wide state (auth, config, data) | global-state.md |
| Screen not reacting to state changes | global-state.md → hooks-reference.md |
| App startup / splash / boot sequencing | app-bootstrap.md |
| Global states that depend on other global states | app-bootstrap.md |
| Firebase/SDK not initialized race | app-bootstrap.md |
| Where do uncaught submit/compute errors go? | error-handling.md |
| Retry dialog for failed operations | error-handling.md |
| Map backend errors to form field messages | error-handling.md |
| Declaring routes / typed navigation | navigation.md |
| Navigate in reaction to global state (post-login redirect) | navigation.md |
| Screen hosted in bottom sheet / dialog returning a result | navigation.md |
| Form submission with loading/error | async-patterns.md |
| Settings/preferences screen with per-toggle persistence | async-patterns.md (usePersistedState) + hooks-reference.md |
| Form with validation (multi-field, submit gating) | async-patterns.md |
| Async data with loading spinner | async-patterns.md |
| Paginated list, infinite scroll, cursor/page/token pagination | paginated.md |
| Pull-to-refresh on a list | paginated.md (PaginatedComputedStateWrapper) |
| Paginated search with debouncing | paginated.md (keys + debounceDuration) |
| Optimistic updates on a paginated list | paginated.md (optimistic overlay) or complex-state-examples.md shape 3 |
| Stream that should drive UI | hooks-reference.md (useMemoizedStream) |
| Derived value from other state | hooks-reference.md (useMemoized) |
| Widget with expand/collapse, animation, lazy load | composable-hooks.md (widget-level hook) |
| Reusable widget used N times on one screen | composable-hooks.md (composed hook state) |
| Screen state polluted with per-tile logic | composable-hooks.md (widget-level hook) |
| Paging, specialized text field, reusable control | composable-hooks.md (composed hook state) |
| TextEditingController / FocusNode handling | flutter-conventions.md |
| Testing a screen state hook | testing.md |
| Testing global state and state interactions | testing.md |
| Injecting a service into a screen | di-services.md |
| Registering a new service or state | di-services.md |
Using List / Map / Set instead of immutable | flutter-conventions.md |
| Lambda style, naming, widget extraction | flutter-conventions.md |
| Generated code out of date | flutter-conventions.md |
| Replacing StatefulWidget | screen-state-view.md + hooks-reference.md |
| State hook is too large (>300 lines, >10 useState) | composable-hooks.md (screen hook decomposition, Pattern 3) |
| Per-item state (list tile with expand / async / drafts) | composable-hooks.md (per-item state archetypes) |
| Complex multi-domain or multi-step screen state - what should it look like? | complex-state-examples.md |
| Screen with bottom nav / tabs / sub-pages the user switches between | multi-page-shell.md |
| Inner tab/page is a monolithic HookWidget with inline logic | multi-page-shell.md |
| Bottom nav / tab index needs to survive deep links or cross-screen jumps | multi-page-shell.md + global-state.md |
useState, useProvided, useInjected in *_view.dart. View is always StatelessWidget.state - no extra onBack, onNavigate, or other parameters. All callbacks are fields on the State class.build() reads BuildContext (for navigation/dialogs/args) and calls exactly one hook: useXScreenState(...). Screen must NOT call useInjected, useProvided, useEffect, useState, or any other hook (single exception: one useEffect whose only job is consuming one-shot event fields - see navigation.md).useProvided<NavigatorKey> or useInjected<AppRouter>. State hook receives navigation as void Function() / Future<T?> Function() parameters. See navigation.md.*_screen_state.dartuseProvided / useInjected only in screen state hooks - not in Screen, not in View, not passed down as parametersIList/IMap/ISet, never List/Map/Set, including static data (applies when the project declares fast_immutable_collections; brownfield exception in flutter-conventions.md §2)useState<bool> + try/catch/finally for data loading. Always useAutoComputedState.useState<List<T>> + hasMore + cursor for paginated lists. Always usePaginatedComputedState + PaginatedComputedStateWrapper. See paginated.md.ButtonState by hand for submit-backed buttons - always submitState.toButtonState(onTap: ...) or useSubmitButtonState (only the latter guards re-entrant taps - see async-patterns.md).useMemoized over useEffect for derived state - effects cascade; memoized values don'tuseState calls across the widget treeTextEditingController in useMemoized + useListenable - always useFieldState in the state hook + TextEditingControllerWrapper in the View. See flutter-conventions.md.widget/ folder, using widget-level hook pattern from composable-hooks.md when they have own state_providers), or extract pure helpers/derivations to services. See global-state.md.The one sanctioned exception - the lightweight tier. A trivial, self-contained dialog
or component (roughly 30 lines, no navigation fan-out) may be a single-file HookWidget
calling useInjected / useSubmitState directly in build. The moment it grows - second
action, derived state, navigation, anything that smells like logic - promote it to the
full Screen/State/View split. Three files stays the default for every screen.
See screen-state-view.md (lightweight tier).
After generating a screen, run down this list. Each item is a one-line check for a rule above (or a reference pattern) - see the rule for the full rationale and fix:
state? → "View constructor takes ONLY state"useXScreenState(...)? → "Screen = pure wiring" (exception: one useEffect consuming one-shot event fields - see navigation.md)HookWidget or calls hooks? → "View never calls hooks"useState<bool>(true) / useState<T?>(null) for loading/error? → "No manual loading state"List/Map/Set in the State class? → "No mutable collections in State classes"useState<List<T>> + hasMore + cursor + manual load effect? → "No hand-rolled pagination"ButtonState(...) next to a submit state? → "Never construct ButtonState by hand"useProvided<NavigatorKey> / useInjected<AppRouter> in a state hook? → "Navigation flows Screen → State → View as callbacks"useXScreenState(...) signature accepts BuildContext? → same rule; replace with typed callbacks built in the ScreenuseMemoized(TextEditingController.new) + useListenable? → "Never wrap TextEditingController"useEffect + useState? → "Prefer useMemoized over useEffect"*ScreenState classes for one screen, or scattered useState in the View? → "One State class per screen"*_screen_state.dart beyond Color / Duration / domain types? → "State never imports widgets"useState? → decompose; composable-hooks.md Pattern 3useSubmitState() in one hook? → group mutually exclusive actions; async-patterns.mdwidgets/*.dart extending HookWidget and calling useProvided/useInjected? → mis-classified View; rename to view/x_screen_view.dart, see screen-state-view.md Common PitfallsBuilt on utopia_hooks by UtopiaSoftware.
references/app-bootstrap.md (opens in a new tab)references/async-patterns.md (opens in a new tab)references/complex-state-examples.md (opens in a new tab)references/composable-hooks.md (opens in a new tab)references/di-services.md (opens in a new tab)references/error-handling.md (opens in a new tab)references/flutter-conventions.md (opens in a new tab)references/global-state.md (opens in a new tab)references/hooks-reference.md (opens in a new tab)references/multi-page-shell.md (opens in a new tab)references/navigation.md (opens in a new tab)references/paginated.md (opens in a new tab)references/screen-state-view.md (opens in a new tab)references/testing.md (opens in a new tab)references/utopia-cli.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub utopia-uss/utopia-flutter-skills --plugin utopia-hooks