/flutter:ui-states-and-feedbackfrom Flutter Skills
Enforces loading/empty/error/content UI patterns using AsyncValue or sealed view states. Covers skeletons, refresh, undo, snackbars, banners, dialogs, and accessibility announcements.
Ships in Flutter Skills. 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.
Most of a screen's code is the happy path; most of its defects are not. This skill
governs everything a screen shows when there is no data yet, no data at all, no data
matching the filter, a failure, or a write that just returned — and which surface each
of those is allowed to use. The first-frame/cold-start path belongs to
app-startup-and-bootstrap; the error values belong to error-handling-typed-results.
This skill is only about how they are rendered and announced.
switch over an AsyncValue
or a sealed view state. Never a triple of isLoading, error, items booleans.
WHY: separate flags make impossible states representable — loading and error, empty
and loading — and every such combination eventually renders.FutureBuilder or
StreamBuilder wrapped around a repository call in the middle of a widget tree.
WHY: state scattered across the tree cannot be tested without pumping widgets, and
rebuilds re-fire the future. See state-management-riverpod, widget-composition.e.toString(), no stack trace, no failure class
name in the UI. Map the typed Failure.code to a localized message via ARB. WHY: a
raw exception is untranslatable, unactionable, and often leaks paths or ids.ref.invalidate(provider)), go
back, or change the input — and retry must preserve scroll position, filters, and
entered text. WHY: a dead-end error screen turns a transient failure into an uninstall.AsyncValue.when's skipLoadingOnRefresh default, or
valueOrNull + isRefreshing). WHY: replacing a list with a spinner loses the user's
place and reads as data loss.design-system-structure.)barrierDismissible: false. WHY: Undo is
faster for the 99% who meant it and safer for the 1% who did not. See
error-handling-typed-results for the soft-delete write path.showDialog/showModalBottomSheet return Future<T?> — null means dismissed,
and it is its own outcome. Switch over a sealed result and handle dismissal
explicitly; never ?? true. WHY: ?? true silently converts a tap outside the
dialog into a confirmed deletion.ScaffoldMessenger/Navigator before the await, guard mounted after.
Then show the snackbar. WHY: the BuildContext may be gone when the write returns —
this is the exact use_build_context_synchronously hole (async-safety).liveRegion: true or SemanticsService.announce,
and auto-dismissal is lengthened or removed when
MediaQuery.accessibleNavigationOf(context) is true. WHY: a 4-second snackbar is
invisible to a screen-reader user mid-sentence. Announcements are best-effort per
platform — never the only channel for something important.class NotesScreen extends ConsumerWidget {
const NotesScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
final notes = ref.watch(notesProvider);
// ONE switch. skipLoadingOnRefresh (default true) keeps the list on screen
// while it reloads — the refresh path never falls into `loading`.
return notes.when(
loading: () => const NotesSkeleton(), // shaped like the list, delayed
error: (error, _) => ErrorStateView(
// A typed Failure's stable code → a localized string. Never e.toString().
message: l10n.failureMessage(error is Failure ? error.code : 'error.unknown'),
onRetry: () => ref.invalidate(notesProvider),
),
data: (notes) => notes.isEmpty
? EmptyStateView( // "nothing yet" ≠ "no matches"
title: l10n.notesEmptyTitle,
action: l10n.notesEmptyCreate,
onAction: () => ref.read(notesProvider.notifier).createDraft(),
)
: NotesListView(notes: notes),
);
}
}
A screen with filters resolves filtered-empty before empty: the ViewModel knows
whether a filter is active, so the View never has to guess why the list is short.
Complete file, including the delayed skeleton and the partial-failure row state:
examples/async_state_view.dart.
| Surface | Lifetime | Use it for | Never use it for |
|---|---|---|---|
| Inline (in the field/region it concerns) | Until resolved | Validation, a per-item failure, an empty region | A global condition |
| Snackbar | Seconds, auto-dismiss | A completed action + its Undo; a non-critical, already-recovered failure | Anything the user must act on, or anything they'd want to re-read |
Banner (showMaterialBanner) | Until dismissed | An app-level condition that persists: offline, expired data, a degraded mode | A transient confirmation |
| Dialog / modal sheet | Blocks until resolved | A decision that must resolve now, an irreversible confirmation | Showing information, reporting a result, or anything you could render inline |
A per-item failure inside a list is an inline row state, not a screen state — one row that failed to sync must not replace the other forty-nine.
Future<void> _delete(BuildContext context, WidgetRef ref, NoteId id) async {
// Capture BEFORE the await — the context may be gone when the write returns.
final messenger = ScaffoldMessenger.of(context);
final l10n = AppLocalizations.of(context);
final result = await ref.read(notesProvider.notifier).softDelete(id);
if (!context.mounted) return;
switch (result) {
case Ok():
messenger.clearSnackBars(); // don't queue behind an older one
messenger.showSnackBar(SnackBar(
content: Text(l10n.noteDeleted),
// Undo instead of a pre-emptive "Are you sure?" dialog.
action: SnackBarAction(
label: l10n.undo,
onPressed: () => ref.read(notesProvider.notifier).restore(id),
),
// Auto-dismiss is a barrier for screen-reader and switch users.
duration: MediaQuery.accessibleNavigationOf(context)
? const Duration(seconds: 30)
: const Duration(seconds: 6),
));
case Err(:final failure):
// A failure the user must act on is NOT a snackbar.
messenger.showMaterialBanner(deleteFailedBanner(l10n, failure.code));
}
}
SnackBarAction is the Undo affordance for a soft delete: the row is flagged, not
destroyed, and the hard delete happens later (error-handling-typed-results). An Undo
that cannot actually restore the record is worse than no Undo.
// Sealed outcome — dismissal is a real case, not a missing value.
sealed class ConfirmOutcome {}
final class ConfirmAccepted implements ConfirmOutcome {}
final class ConfirmDeclined implements ConfirmOutcome {}
final class ConfirmDismissed implements ConfirmOutcome {} // tapped outside / back
final outcome = await showDialog<ConfirmOutcome>(
context: context,
barrierDismissible: false, // a decision that must resolve does not evaporate
builder: (_) => PermanentDeleteDialog(count: selected.length),
) ??
ConfirmDismissed(); // null == dismissed — NEVER `?? ConfirmAccepted()`
The dialog's title names the consequence and the count; the confirming button carries the verb ("Delete permanently"), never "OK". Destructive verbs and the count are what a user reads before tapping — "Are you sure?" tells them nothing.
isLoading + errorMessage + items as three fields — impossible states become
representable and eventually render.FutureBuilder over a repository call inside build() — refires on every rebuild
and cannot be tested without a widget pump.Text('${e}') or a stack trace in the UI — untranslatable, unactionable, leaky.?? true on a dialog's result — a tap outside becomes a confirmed destruction.ScaffoldMessenger.of(context) after an await with no mounted guard — throws
or targets a dead tree (async-safety).switch/when; no bool triple; no FutureBuilder over a repository call.Failure.code mapped through ARB; no exception,
class name, or stack trace is rendered.barrierDismissible: false
dialog that names the consequence and count.?? <affirmative>.ScaffoldMessenger/Navigator captured before every await; mounted guarded
after; snackbars cleared before showing a new one.liveRegion/SemanticsService.announce), and
auto-dismiss is extended under accessibleNavigation.state-management-riverpod — where the state is decided, and AsyncValue ownership.error-handling-typed-results — the Result/Failure values rendered here, and the
soft-delete/Undo write path.async-safety — capturing context before an await and guarding mounted after.widget-composition — dumb Views, extracted const state widgets, no logic in build().accessibility-as-code — semantics, live regions, and the a11y flags read from
MediaQuery.motion-and-haptics — the sensory half of feedback: what the transition into each of
these states animates, the one haptic per committed action, and the reduced-motion path.i18n-rtl-l10n — every message in ARB, including failure-code messages.app-startup-and-bootstrap — the first-frame/splash path this skill does not cover.widget-golden-and-a11y-testing — pumping and asserting each of the four states.design-system-structure — where the skeleton, banner, and empty-state components live.ScaffoldMessenger: https://api.flutter.dev/flutter/material/ScaffoldMessenger-class.htmlSemanticsService.announce: https://api.flutter.dev/flutter/semantics/SemanticsService/announce.htmlAsyncValue (when, skipLoadingOnRefresh, valueOrNull): https://riverpod.dev/docs/essentials/async_initializationWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ui-states, loading-ui, error-ui, empty-state, snackbar, dialog
npx claudepluginhub zakariaf/flutter-skills --plugin flutter40 skills in this plugin
/accessibility-as-codeEnforces accessibility as a correctness property authored into each widget — Semantics(button/label) or ExcludeSemantics on every node, a11y state read from MediaQuery not app state, never MediaQuery.withClampedTextScaling / textScaleFactor / FittedBox / TextOverflow.ellipsis to fit a label, non-color redundant channels (icon+label+shape+text) for every state, contrast against composited backgrounds (4.5:1 body / 3:1 large), 44px single-tap targets, OrdinalSortKey traversal, and honoring boldText / reduce-motion. Use when adding a GestureDetector/InkWell or any tap target, adding an Icon or Image, reaching for withClampedTextScaling/FittedBox/ellipsis/textScaleFactor to make text fit, encoding state via color, sizing type, ordering focus traversal, or reviewing any View for screen-reader/switch/low-vision support./adaptive-layoutEnforces adapting layout by available CONSTRAINTS/size, never device or platform checks — LayoutBuilder + MediaQuery.sizeOf/paddingOf/viewInsetsOf (not .of) for narrow rebuilds, Material 3 window size classes (compact <600, medium 600-840, expanded 840-1200, large >1200) as the breakpoint vocabulary, navigation affordance chosen by width (NavigationBar → NavigationRail → NavigationDrawer), list-detail single-pane-vs-two-pane, readable max-width via ConstrainedBox, Flexible/Expanded/FractionallySizedBox over fixed widths, SafeArea + display cutouts + keyboard insets, never lock orientation, foldable/hinge awareness via MediaQuery.displayFeatures, and golden-matrix verification across sizes. Use when building responsive or adaptive UI, tablet/desktop/foldable support, master-detail or two-pane screens, a NavigationRail-vs-BottomNav shell, breakpoints, LayoutBuilder, MediaQuery sizing, SafeArea/cutouts, or fixing overflow at large widths./ads-and-iap-monetizationEnforces opt-in, rewarded-first monetization over the service seam — a rewarded view grants exactly one benefit and only on a genuine reward outcome (a sealed Rewarded/Dismissed/NoFill), earn loops capped per day against an injected Clock, the earn control preloaded and hidden unless an ad is loaded so a fresh account never dead-ends on "no ads available" (a Guideline 2.1 risk), interstitials only at a natural break under a count-and-elapsed cap owned by the service so callers stay dumb, no banner on the primary work surface, one non-consumable unlock plus Restore re-checked each launch and committed through the single write path before the UI reacts, one derived isEntitled provider as the only gate, and the entitlement restored BEFORE the ad SDK initializes so a paying user never starts it, resolves consent, or sees a tracking prompt. Use when adding ads, wiring a rewarded earn loop, placing an interstitial, building a paywall, gating an entitlement, or setting up ad units./app-startup-and-bootstrapEnforces a fixed main() cold-launch order — crash-log sink + FlutterError.onError + PlatformDispatcher.onError installed BEFORE any code that can throw, settings/theme read before runApp so the first frame paints correct, real infra constructed in a composition-root bootstrap() and injected via ProviderScope overrideWithValue over throwing placeholder providers, non-blocking warm-up deferred to addPostFrameCallback, exactly two error handlers with NO runZonedGuarded, ProviderException unwrapped before logging, and a WidgetsBindingObserver that flushes durable state on background/resume. Use when editing lib/main.dart, main_<flavor>.dart, bootstrap.dart or app.dart, reordering anything in main(), adding a splash/onboarding/permission gate, restoring theme before first paint, wiring a DB or service into ProviderScope, handling app-lifecycle background/resume flushes, or chasing cold-start latency, ANRs, or first-frame jank./async-safetyEnforces no-silent-failure async discipline in Flutter/Dart — the arrow-callback Future-drop hole no lint catches (`onTap: () => vm.save(x)`), void-returning event handlers, a mounted/ref.mounted guard after EVERY await before touching BuildContext, capturing Navigator/ScaffoldMessenger before the gap, honest `unawaited()` that always ends in catchError, no empty/bare catches, `rethrow` over `throw e`, and disposing every StreamSubscription/StreamController/Timer/sink. Use when writing or reviewing async/await, wiring onTap/onPressed/onSubmitted or any VoidCallback, touching BuildContext after an await, writing initState/dispose/addPostFrameCallback, adding a Timer or Future.delayed, writing a try/catch, or seeing use_build_context_synchronously, cancel_subscriptions, close_sinks, unawaited_futures, or discarded_futures./ci-pipeline-and-gatesEnforces a lean GitHub Actions Flutter CI where every gate maps to one named release-blocking contract — pinned runner + subosito/flutter-action@v2 toolchain, dart format --set-exit-if-changed, flutter analyze --fatal-infos, build_runner and drift schema freshness (git diff --exit-code), flutter test --test-randomize-ordering-seed random, static import/banned-string greps that catch what runtime can't, coverage-as-report-never-a-gate with the upward-lie fixed, verify-never-bless goldens (no --update-goldens in CI), and an honest statement of what CI cannot prove (audio, real fonts, on-device behaviour). Use when editing .github/workflows/*.yml, adding or removing a job or step, wiring a codegen/schema/format/analyze/coverage gate, writing a grep-based policy test or gate script under test/policy or tool/, pinning action versions, or claiming CI proves something it can't.Other plugins' skills for the same job