Dart/Flutter Patterns
When to Use
Use this skill when:
- Starting a new Flutter feature and need idiomatic patterns for state management, navigation, or data access
- Reviewing or writing Dart code and need guidance on null safety, sealed types, or async composition
- Setting up a new Flutter project and choosing between BLoC, Riverpod, or Provider
- Implementing secure HTTP clients, WebView integration, or local storage
- Writing tests for Flutter widgets, Cubits, or Riverpod providers
- Wiring up GoRouter with authentication guards
How It Works
This skill provides copy-paste-ready Dart/Flutter code patterns organized by concern:
- Null safety — avoid
!, prefer?./??/pattern matching - Immutable state — sealed classes,
freezed,copyWith - Async composition — concurrent
Future.wait, safeBuildContextafterawait - Widget architecture — extract to classes (not methods),
constpropagation, scoped rebuilds - State management — BLoC/Cubit events, Riverpod notifiers and derived providers
- Navigation — GoRouter with reactive auth guards via
refreshListenable - Networking — Dio with interceptors, token refresh with one-time retry guard
- Error handling — global capture,
ErrorWidget.builder, crashlytics wiring - Testing — unit (BLoC test), widget (ProviderScope overrides), fakes over mocks
Examples
Practical, production-ready patterns for Dart and Flutter applications. Library-agnostic where possible, with explicit coverage of the most common ecosystem packages.
1. Null Safety Fundamentals
Prefer Patterns Over Bang Operator
Avoid late Overuse
2. Immutable State
Sealed Classes for State Hierarchies
Freezed for Boilerplate-Free Immutability
3. Async Composition
Structured Concurrency with Future.wait
Stream Patterns
BuildContext After Await
4. Widget Architecture
Extract to Classes, Not Methods
const Propagation
Scoped Rebuilds
5. State Management: BLoC/Cubit
6. State Management: Riverpod
7. Navigation with GoRouter
8. HTTP with Dio
9. Error Handling Architecture
10. Testing Quick Reference
References
- Effective Dart: Design
- Flutter Performance Best Practices
- Riverpod Documentation
- BLoC Library
- GoRouter
- Freezed
- Skill:
flutter-dart-code-review— comprehensive review checklist - Rules:
rules/dart/— coding style, patterns, security, testing, hooks


