/flutter:scaffold-feature-modulefrom Flutter Skills
Scaffolds a feature module with a fixed folder structure: dumb View, 1:1 Notifier/AsyncNotifier ViewModel, widgets, scoped providers, typed go_router route, and ARB locale parity. Use when adding a screen, tab, or feature folder.
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; scripts run unread.
Stand up one feature the same way every time: a folder lib/features/<feature>/ whose
presentation/ holds a dumb View, its 1:1 Notifier/AsyncNotifier ViewModel, leaf widgets/, and
scoped providers (feature-local models live in an optional domain/). A feature is a folder, not a
package. It reads shared repositories from lib/data/ and shared foundation from lib/core/, routes
every write through them, and depends only downward — never sideways into another feature.
(The single-package tree is owned by project-structure-and-packages.)
Agnostic core (holds under any state library): the View is dumb; one ViewModel per feature owns private mutable state and exposes intent methods that assign a new immutable value; reads derive from the repository (the single source of truth), writes go through one repository method (the single write path, persist-before-publish); the feature depends on abstractions and navigates by route ID. The Riverpod-first "how" below wires that with Notifiers, scoped StreamProviders, and providers-as-DI.
Read the reference for the task at hand:
references/anatomy-and-wiring.md — the fixed folder shape, the Notifier + scoped stream, watch/read/listen, family+autoDispose vs keepAlive, the single write path, and the ViewModel test.references/routing-and-l10n.md — typed go_router registration (path params, not state.extra) and the ARB parity workflow.references/add-persisted-record.md — the optional model → table → DAO → repository chain when the feature reads a brand-new record (defers to persistence-drift).Run scripts/scaffold_feature.sh <feature> to generate the skeleton, then scripts/verify_feature.sh before a PR.
lib/features/<feature>/, lower_snake_case, named
for the screen (tasks, task_detail, settings, onboarding). A new folder is a normal
addition; a new package is a deliberate boundary decision (see project-structure-and-packages).
Do not invent numbered-folder or fixed-package-count conventions. The app package does not use
lib/src/ — that is a multi-package convention (see project-structure-and-packages).lib/features/<feature>/presentation/:
<feature>_screen.dart (the dumb View), <feature>_notifier.dart (the 1:1 Notifier/AsyncNotifier
ViewModel — file name = its primary declaration, per naming-conventions), widgets/ (leaf views),
and <feature>_providers.dart (providers scoped to this feature, never global). A feature-local
model lives in an optional domain/<feature>.dart. Predictable shape = a reviewer finds any piece
in one second.ifs, layout, animation, and navigation. No repository call, no try/catch
business logic, no unit math or formatting in build(). Logic lives in the ViewModel..watch() in a scoped StreamProvider.
Never touch Drift, secure storage, or a platform channel from a widget or ViewModel. Scope the
stream by its key (an owner/parent id, a time window) so one write never re-emits app-wide.ref.watch in build, ref.read in callbacks, ref.listen for one-shot effects (SnackBar,
navigate). Watching in a callback re-subscribes; reading in build misses rebuilds. (See
state-management-riverpod for the full split.)family + autoDispose; singletons are keepAlive. Any provider scoped to a
specific entity/session is family-keyed on a stable equatable value and autoDisposed so it
dies with its screen. Never an un-keyed "current thing" provider; never autoDispose the
app-scope db/service singletons.setState, no manual cache poke, no "save later".Map never reaches a ViewModel or widget. Measured quantities are value objects
(see value-objects-money-and-units) — never a bare double for money.AsyncValue. Repositories return a sealed Result/
Failure; the ViewModel maps it to AsyncData/AsyncError; the View switches exhaustively and
localizes the Failure at the presentation edge — never a raw exception string. (See
error-handling-typed-results.)TypedGoRoute/GoRouteData; carry deep-linkable identity in path params (:taskId), never
state.extra (null on cold start/OS restore). Full-screen add/edit flows set
parentNavigatorKey: rootNavigatorKey. The router itself — shell/branch structure, redirect/auth
guards, deep links, transitions — is owned by navigation-and-routing; this feature only
registers its route into it.redirect decides what is on screen. A controller that pushes a
route couples logic to navigation and breaks headless tests.DateTime.now() in a feature. The ViewModel reads a Clock
provider so a whole flow is assertable with a pinned fake clock. (See async-safety.)EdgeInsetsDirectional/AlignmentDirectional
— never .left/.right, Alignment.centerLeft, or TextAlign.left. Every user-facing string comes
from gen-l10n across all locale ARBs with key + placeholder parity. (See i18n-rtl-l10n.)ProviderContainer.test() +
overrideWith a fake repository and clockProvider.overrideWithValue(Clock.fixed(t)); no widget
pump; verify wiring and UI-state mapping only. (See testing-strategy.)Default to hand-written providers (state-management-riverpod owns the discipline; @riverpod
codegen is an optional alternative, not the default). Colocate the scoped stream and the command
Notifier in <feature>_providers.dart / <feature>_notifier.dart. Full file:
examples/tasks_notifier.dart.
// features/tasks/presentation/tasks_providers.dart — reactive backbone, scoped so one write is not app-wide.
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:app/core/result.dart'; // Result, Ok, Err, Failure (shared foundation, lib/core/)
import 'package:app/data/task_repository.dart'; // taskRepositoryProvider (keepAlive; lives in lib/data/)
import '../domain/task.dart'; // feature-local immutable model (value objects, not rows)
/// Wrap the repository's scoped `.watch()` in a family StreamProvider, keyed by projectId.
/// `.autoDispose` frees the subscription when the screen unmounts. The repository maps rows ->
/// domain models at the boundary; this never sees a Drift row.
final taskListProvider =
StreamProvider.autoDispose.family<List<Task>, String>((ref, projectId) =>
ref.watch(taskRepositoryProvider).watchTasks(projectId));
// features/tasks/presentation/tasks_notifier.dart — the 1:1 ViewModel: command state + writes.
final tasksNotifierProvider =
AsyncNotifierProvider.autoDispose<TasksNotifier, void>(TasksNotifier.new);
class TasksNotifier extends AsyncNotifier<void> {
@override
FutureOr<void> build() {} // no synchronous heavy work here
/// A command the View binds. The write goes through ONE repository method (single write path);
/// the typed Result is mapped to AsyncValue for the View to switch on exhaustively.
Future<void> add(Task draft) async {
state = const AsyncLoading();
final Result<void, Failure> result =
await ref.read(taskRepositoryProvider).addTask(draft);
state = switch (result) {
Ok() => const AsyncData(null),
Err(:final failure) => AsyncError(failure, StackTrace.current),
};
// No manual republish: the committed write makes the Drift stream re-emit and the list rebuilds.
}
}
The View watches the scoped stream, renders inside .when, and calls ref.read(...notifier) from
callbacks. It ref.listens the controller for one-shot effects. Full file: examples/tasks_screen.dart.
class TasksScreen extends ConsumerWidget {
const TasksScreen({required this.projectId, super.key});
final String projectId;
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
ref.listen(tasksNotifierProvider, (prev, next) { // one-shot effects only
if (next case AsyncError(:final error)) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(localizeFailure(l10n, error))), // typed Failure -> localized text
);
}
});
final async = ref.watch(taskListProvider(projectId)); // watch in build
return Scaffold(
appBar: AppBar(title: Text(l10n.tasksTitle)),
body: async.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => FailureView(message: localizeFailure(l10n, e)),
data: (tasks) => tasks.isEmpty
? EmptyState(title: l10n.tasksEmptyTitle)
: ListView.builder(
padding: const EdgeInsetsDirectional.symmetric(horizontal: 16, vertical: 8),
itemCount: tasks.length,
itemBuilder: (context, i) => TaskTile(
task: tasks[i],
onTap: () => TaskDetailRoute( // navigate by ID, from the View
projectId: projectId,
taskId: tasks[i].id,
).go(context),
),
),
),
);
}
}
TypedGoRoute, path-param identity,
parentNavigatorKey: rootNavigatorKey for full-screen flows), then regenerate typed routes with
build_runner. See references/routing-and-l10n.md.If the screen needs a record that does not exist yet, add the chain before wiring the feature:
an immutable value type (pure, no store import) → a Drift table with schema invariants → a DAO that
maps rows to the value type → a repository method that opens one transaction. Then the feature reads
its scoped .watch() stream as usual. The full ritual lives in persistence-drift and run-migration;
references/add-persisted-record.md is the short bridge.
<feature>_view_model.dart/*Controller on the Riverpod path, or naming the View <feature>_view.dart when the convention is _screen.dart. One primary public type per file, file name = its declaration (naming-conventions); the Riverpod ViewModel is <feature>_notifier.dart → <Feature>Notifier.try/catch business logic in build(). The View reads one controller and renders; logic lives in the ViewModel.setState, a manual cache poke, or a debounced "save later". Every write is one repository method that persists, then the stream re-emits.autoDispose on app-scope singletons. Per-key state is family + autoDispose; singletons are keepAlive.DateTime.now() in a feature. Read an injected Clock provider so flows are assertable.state.extra for deep-linkable identity, or Navigator.push of a primary flow. Path params + a typed GoRoute; the View/redirect decides navigation, not the controller.EdgeInsetsDirectional + strings from gen-l10n.Notifier in tests instead of faking the repository. Fake the seam; test the wiring.lib/features/<feature>/ with the fixed anatomy under presentation/: <feature>_screen.dart (dumb View), <feature>_notifier.dart (1:1 Notifier/AsyncNotifier), widgets/, scoped <feature>_providers.dart.try/catch in build(); .when surfaces a calm error..watch(); per-key providers are family-keyed on a stable value and autoDisposed; singletons are keepAlive.Map reaches a widget; money is not a bare double.Result/Failure mapped to AsyncValue; the View switches exhaustively and localizes the Failure at the edge.Clock; no DateTime.now() in the feature.GoRoute is registered in the single router; identity in path params; full-screen flows set parentNavigatorKey; no navigation from the ViewModel.Directional-only.ProviderContainer.test() + a fake repository and a fixed Clock (clockProvider.overrideWithValue(Clock.fixed(t)), not a mocked Notifier).dart format + dart analyze --fatal-infos clean; scripts/verify_feature.sh passes.flutter-architecture — the layer model and downward-only DAG this scaffold obeys.state-management-riverpod — the Notifier/AsyncNotifier discipline, watch/read/listen, family+autoDispose, manual-providers-first.navigation-and-routing — owns the single go_router this feature registers its typed route into.forms-and-input — the Form/validation/focus discipline for the add/edit flow this feature launches.widget-composition — dumb Views, small const widget classes, structural layout.error-handling-typed-results — the sealed Result/Failure spine surfaced as AsyncValue.persistence-drift and run-migration — the repository/DAO/table/migration ritual behind a new record.i18n-rtl-l10n — the ARB parity + Directional-geometry contract.value-objects-money-and-units — the canonical value objects the ViewModel passes.testing-strategy — faking the repository (and clockProvider) to test the ViewModel headlessly.project-structure-and-packages — owns the single-package tree; when a foundation genuinely earns a package instead of a folder.Using the official Flutter-guide stack (package:provider + ChangeNotifier)? The rules are
identical; only the wiring changes:
ChangeNotifier; intent methods mutate private fields and call
notifyListeners() once at the end (still one immutable state snapshot's worth of change per call).ChangeNotifierProvider at the feature route; the View reads it with
context.watch<TasksViewModel>() in build and context.read<TasksViewModel>() in callbacks —
the same watch-in-build / read-in-callbacks split as Riverpod.Stream and fold it with a StreamProvider (the provider
package's StreamProvider, or StreamBuilder) — do not cache a mutable copy in the ViewModel;
derive on emit.family+autoDispose: create the ChangeNotifierProvider at the
screen so it disposes with the route; keep app-scope services in a root provider.ChangeNotifier.dispose().Everything else — dumb View, single write path, typed Result/Failure, path-param routing,
injected clock, ARB parity, Directional geometry, faking the repository in tests — is unchanged.
examples/tasks_notifier.dart (opens in a new tab)examples/tasks_screen.dart (opens in a new tab)references/add-persisted-record.md (opens in a new tab)references/anatomy-and-wiring.md (opens in a new tab)references/routing-and-l10n.md (opens in a new tab)scripts/scaffold_feature.sh (opens in a new tab)scripts/verify_feature.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
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