Standards for building maintainable Flutter apps, distilled from the official Flutter architecture guide and LeanCode's experience shipping 40+ Flutter projects (including a 30-developer banking app). Apply these when writing new code; when touching existing code, prefer consistency with the surrounding codebase and raise conflicts with these standards rather than silently rewriting.
Read the reference file that matches the task. Read more than one when tasks overlap (e.g. a new feature touches both structure and coding style).
| Task | Read |
|---|---|
| Design layers, decide where logic lives, MVVM, repositories/services | references/architecture-layers.md |
| Create/organize a feature, folder structure, state management wiring | references/feature-structure.md |
| Write or review Dart/Flutter code, widgets, tests, lints | references/dart-coding-practices.md |
| Multi-team/multi-package apps, monorepo, navigation, localization, API contracts, E2E tests | references/enterprise-scale.md |
| App localization setup, reusable UI package string ownership, language picker visibility | references/localization-package-boundaries.md |
For a quick task (small widget fix, one-line review comment), the core rules below may be enough on their own.
View → ViewModel → Repository → Service. Lower layers never import upper
layers. Repositories never depend on each other.BuildContext.blocs/, widgets/, models/ buckets that scatter a
feature across the tree.Container. Use Padding,
SizedBox, ColoredBox, DecoratedBox, Center — they are const-able
and self-describing. Container is fine only when combining several
properties at once.if (x case final v?)), switch
expressions with exhaustiveness, records and destructuring, collection
if/for/spreads instead of .add() loops, expression bodies for
pass-through async functions (no redundant async/await).Sliver so misuse in the wrong
scroll context is caught at a glance.isEmpty, throwsA,
isA, completion) and minimize dependencies — plain Text/SizedBox
over design-system widgets in test fixtures. Test cubits/view models in
isolation from the widget tree.// ignore: gets a reason on the same or preceding line. Log
errors with dedicated error/stackTrace parameters, never string
interpolation.Check, in order of importance:
BuildContext in business logic?// ignore:, string-interpolated error logs, deprecated
patterns still spreading?leancode_lint or equivalent + custom rules) —
retrofitting is far more expensive.Defaults that these standards assume (swap for project-local equivalents when the codebase already uses something else):
bloc (Cubit) + freezed for union-type states;
bloc_presentation for one-off UI eventsprovider scoped to widget subtrees (accepting its lack of
compile-time safety as the lesser evil)flutter_hooks
melos
flutter_localizations + intl with .arb filesleancode_lint
patrol
The official Flutter guide is state-management-agnostic (MVVM with ChangeNotifier works too); what matters is the layer separation, not the package. See the reference files for rationale and trade-offs.