Flutter/Dart Code Review Best Practices
Library-agnostic review checklists for Flutter/Dart apps — any state management, routing, or DI solution. Detalhes em references/.
When to Activate
- Reviewing Flutter/Dart pull requests or auditing an existing codebase
- Checking widget best practices, state management (BLoC, Riverpod, Provider, GetX, MobX, Signals), or Dart idioms
- Evaluating Flutter app performance, accessibility, or security
- Enforcing clean architecture in a Dart/Flutter project
When NOT to Use
- Native Android (Kotlin) or iOS (Swift) code (use platform-specific skills)
- Backend Dart servers (use
backend-patterns)
Example
// BAD — boolean flag soup allows impossible states
class UserState {
bool isLoading = false;
bool hasError = false; // isLoading && hasError is representable!
User? user;
}
// GOOD — sealed types make impossible states unrepresentable
sealed class UserState {}
class UserLoading extends UserState {}
class UserLoaded extends UserState {
final User user;
const UserLoaded(this.user);
}
class UserError extends UserState {
final String message;
const UserError(this.message);
}
References
references/project-health.md— folder structure, separation of concerns, Dart pitfallsreferences/widgets-state.md— widget decomposition, const/keys, state management, quick-ref tablereferences/perf-testing.md— rebuilds, images, lazy loading, test types and qualityreferences/platform-a11y.md— semantics, screen reader, platform differences, responsivereferences/security-deps.md— secure storage, API keys, pub.dev review, version constraintsreferences/app-concerns.md— navigation, errors, l10n, DI, static analysis, sources
Top-10 Critical Checks
- No business logic in widgets;
build()pure (no I/O, no.listen()) - Sealed/union states, not boolean flags; all variants handled exhaustively
-
consteverywhere possible; consumers scoped narrowly; selectors for rebuilds -
context.mountedafter every async gap; context never stored - Strict analyzer (
strict-casts/inference/raw-types);flutter analyzegreen in CI - Secrets via
--dart-define/env, never hardcoded; HTTPS everywhere - Contrast ≥ 4.5:1, 48px targets, no color-only state signals
- Tests: 80%+ business logic, transitions covered, no shared mutable state