flutter
Scope
Covers Flutter application and Dart package work: widget composition and layout, the three state-management stacks in real use, navigation and deep links, testing at every layer, performance, localization, networking and serialization, Dart 3 language features, analyzer/tooling hygiene, and the Dart↔native boundary (platform channels, Pigeon, FFI).
Not covered: writing native iOS/Android UI or platform SDK code beyond the
channel boundary — use the apple or android skill. Other cross-platform
stacks: React Native and Expo belong to the react-native skill. Also out of
scope: Flutter web hosting/CI/store release, Firebase and other vendor SDKs,
and game engines (Flame). For visual/UX design decisions or web frontends, use
the frontend-design skill instead.
Paths below are relative to this skill's directory.
Core rules
- Detect the stack before touching state: read
pubspec.yaml.flutter_riverpod/hooks_riverpod/riverpod_annotation→ Riverpod;flutter_bloc→ Bloc/Cubit; neither →ChangeNotifier+ListenableBuilder. Two state solutions in one app means two sources of truth for the same screen. - In Riverpod,
StateProvider,StateNotifierProviderandChangeNotifierProviderare legacy — they survive only for migration. New code usesNotifier/AsyncNotifierbehindNotifierProvider/AsyncNotifierProvider. - Put
ProviderScope(or the rootBlocProvider) inrunApp, not insideMyApp: inside the app widget, provider state dies on every root rebuild and tests observe a different tree than production. - Mark every constructor
constthat the analyzer allows, and preferPadding,SizedBox,ColoredBoxoverContainer— a const subtree is skipped during rebuild;Containeris rarely const-able. - Extract widget classes, never
Widget _buildHeader()helpers: a method rebuilds with its parent, cannot be const, and shows up as an anonymous node in DevTools. - Any list that can exceed one screen uses
ListView.builder/GridView.builder/SliverList. AColumn(orListView(children: [...])) builds and lays out every child up front, even the ones nobody scrolls to. - Guard
BuildContextafter everyawait:if (!context.mounted) return;beforeNavigator,ScaffoldMessenger,Theme.ofand friends. The widget may be gone. - No IO, no network calls, no
setStateinsidebuild().buildruns on every dependency change and every frame that invalidates the subtree. - Keep decisions out of widgets: formatting and show/hide are fine, anything that
transforms or decides about data belongs in the notifier/cubit/view model, which never
sees a
BuildContext. - Model state as an immutable value compared by value (
Equatable,freezed, or a sealed hierarchy), and assign new collections (state = [...state, item]). In-place mutation leaves==true and listeners silent. - Dispose what you create: controllers and
FocusNodes indispose(), provider subscriptions and timers inref.onDispose, streams inBloc.close. - Base layout decisions on constraints (
LayoutBuilder) or window size (MediaQuery.sizeOf), never on device type ororientationOf— apps run in split screen, on foldables and in resizable desktop windows. - Parsing fails fast and paths stay portable. An
if (raw case …)inside a parsing loop silently drops malformed input — throwFormatExceptionnaming the bad element instead. File paths go throughpackage:path:p.join,p.splitwith a list pattern (orp.isWithin),p.extension, andp.posix.joinAll(p.split(p.relative(…)))for manifest or URL keys — never'$a/$b',startsWith('x/'),split('/')orreplaceAll(r'\', '/')(references/dart-language.md). - Finish every change with the gate:
dart formaton the files you changed (notdart format .; a repo-wide reformat is a commit of its own), thenflutter analyzewith zero issues, thenflutter test. Analyzer info-level lints count; silence one only with// ignore: <code> — <reason>.
Workflows
add-feature
- Read
pubspec.yamlfor the state, routing, DI and mocking packages already in use (rule 1); follow them instead of introducing a new one. - Place files feature-first:
lib/features/<feature>/{data,domain?,ui}/. Never create top-levelblocs/,widgets/,models/buckets. - Define the immutable state type first (sealed hierarchy, or
AsyncValue<T>when the state is exactly loading/data/error). - Write the service (raw API/plugin wrapper), then the repository (single source of truth, caching, domain models), then the notifier/cubit/view model.
- Add a use case only when logic spans repositories, is genuinely complex, or has more than one caller.
- Build the view last:
ConsumerWidget/BlocBuilder/ListenableBuilderrenders the state exhaustively; callbacks dispatch intents. - Register the route in the router; register dependencies where the app already does.
- Write tests for the notifier/repository logic (see
add-tests). - Gate:
flutter analyzereports no issues andflutter testpasses.
fix-layout-overflow
- Read the first exception in the console, not the cascade.
RenderBox was not laid outis a downstream symptom — scroll up to the real constraint violation. - Match the message to the fix:
RenderFlex overflowed→ wrap the offending child inExpanded(must fit) orFlexible(may shrink); for text also considersoftWrap/overflow.Vertical viewport was given unbounded height→ the scrollable sits in aColumn; wrap it inExpanded, or give it a height, or switch the parent toCustomScrollView.An InputDecorator ... cannot have an unbounded width→ wrap the field inExpandedinside theRow.Incorrect use of ParentDataWidget→Expanded/Flexiblemust be a direct child ofRow/Column/Flex,PositionedofStack.
- If the constraint chain is unclear, run the app and inspect it in DevTools, or set
debugPaintSizeEnabled = truetemporarily. - Hot reload and resize the window through the small and large breakpoints.
- Gate: no exception in the console and no overflow stripes at either breakpoint.
add-tests
- Pick the layer: pure logic and repositories →
test(unit); one widget or screen →flutter_testwidget test; a full user journey on a device →integration_test. - Use the project's mocking library —
mocktailunlesspubspec.yamlalready hasmockito+build_runner. Mock at the repository or client boundary, not the class under test. - With
mocktail, callregisterFallbackValueinsetUpAllfor every custom type used withany(); without it the matcher throws at runtime. - Assert on observable behaviour: emitted states, thrown types
(
throwsA(isA<MyException>())), rendered widgets. A test that only replays a stub cannot fail when the code breaks. - For Riverpod, override the dependency provider in a fresh
ProviderContainerper test andaddTearDown(container.dispose); never mock aNotifierwithimplements. - Gate:
flutter test(ordart testfor a pure Dart package) passes, and the new test fails when the behaviour under test is broken.
upgrade-dependencies
- Run
flutter pub outdatedand read the "Resolvable" column before editing anything. - Upgrade within constraints first (
flutter pub upgrade), then majors one package per commit so a regression has one suspect. - On a version-solving conflict, run
flutter pub depsto find who pins the old version; prefer bumping that package over adependency_overridesentry, and delete any override you add as soon as upstream catches up. - Run
dart fix --dry-run, review, thendart fix --applyfor mechanical deprecations. - Gate:
flutter analyzeclean andflutter testgreen on the upgraded lockfile.
review
- Establish the diff scope, then read the tests in it first: they state what the author believes the code does.
- Walk the Core rules in order — they are ordered by how often each one is the actual defect.
- Check layer discipline: no
BuildContextin logic classes, no service calls from a widget, no feature reaching into another feature's internals. - Check lifecycle: disposal,
context.mounted, provider scope andautoDispose. - Check the rebuild surface: missing
const, whole-objectwatchwhere aselectbelongs, an eager list where a lazy builder belongs. - Report using the Output format below; run
flutter analyzeyourself rather than guessing which findings the analyzer already covers, and skip those it does. - Gate: every finding carries
path:line, a one-line reason, and a concrete fix.
Topic router
| Topic | Read when | File |
|---|---|---|
| Layers, folders, DI | Structuring a project or feature, or deciding where logic lives | references/architecture.md |
| Riverpod | The project depends on any riverpod package | references/state-riverpod.md |
| Bloc / Cubit | The project depends on flutter_bloc | references/state-bloc.md |
| Provider / ChangeNotifier | No Riverpod or Bloc; official MVVM baseline | references/state-provider-changenotifier.md |
| Routing, deep links | Adding routes, tabs, auth redirects, or app links | references/navigation.md |
| Tests | Writing or reviewing unit, widget, integration or E2E tests | references/testing.md |
| Widgets and layout | Building UI, adaptive layouts, or debugging constraints | references/widgets-layout.md |
| Performance | Jank, dropped frames, slow lists, memory growth | references/performance.md |
| Dart 3 language | Patterns, records, sealed classes, primary constructors, package:path | references/dart-language.md |
| Tooling | Analyzer config, dart fix, coverage, pub conflicts | references/dart-tooling.md |
| Localization | Adding .arb strings, plurals, locale handling | references/localization.md |
| JSON and HTTP | Models, parsing, network calls, isolates | references/json-http.md |
| Native interop | MethodChannel, EventChannel, Pigeon, FFI/ffigen | references/platform-channels-ffi.md |
| Accessibility | Semantics, screen readers, text scaling, contrast | references/accessibility.md |
Output format
For review (and any other report on existing code), group findings by file, ordered by
severity, with no preamble:
lib/features/cart/ui/cart_page.dart L42 blocking - `ref.read(cartProvider)` in build() reads once and skips rebuilds. Use `ref.watch`. before: final cart = ref.read(cartProvider); after: final cart = ref.watch(cartProvider); L88 important - ScaffoldMessenger.of(context) used after `await` without `if (!context.mounted) return;`. L15 minor - `EdgeInsets.all(8)` can be const. lib/features/cart/data/cart_repository.dart ✓ pass
Severities: blocking (crash, data loss, wrong behaviour, legacy API that will be
removed), important (rebuild storms, leaks, layer violations), minor (const,
naming, dead code). End with a one-line verdict: ship, ship after blocking fixes, or
rework.
Environment
Flutter SDK on PATH (flutter --version also reports the bundled Dart). Commands used
by the workflows:
bashflutter analyze # zero issues is the bar; add --fatal-infos in CI flutter test # dart test for a pure Dart package flutter pub outdated # before any dependency change dart fix --apply # mechanical deprecation fixes dart format <changed files>
Device-dependent steps (flutter drive, patrol test, adb, xcrun simctl) need a
connected device, emulator or simulator; iOS steps additionally need macOS with Xcode.


