dart-flutter-patterns
Production-ready Dart and Flutter patterns covering null safety, immutable state, async composition, widget architecture, popular state management frameworks (BLoC, Riverpod, Provider), GoRouter navigation, Dio networking, Freezed code generation, and clean architecture. Use when writing or reviewin
By affaan-m · 2,946 installs
npx skills add affaan-m/ecc --skill dart-flutter-patterns
Source repository · Upstream listing
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:
1. Null safety — avoid ! , prefer ?. / ?? /pattern matching
2. Immutable state — sealed classes, freezed , copyWith
3. Async composition — concurrent Future.wait , safe BuildContext after await
4. Widget architecture — extract to classes (not methods), const propagation, scoped rebuilds
5. State management — BLoC/Cubit events, Riverpod notifiers and derived providers
6. Navigation — GoRouter with reactive auth guards via refreshListenable
7. Networking — Dio with interceptors, token refresh with one time retry guard
8. Error handling — global capture, ErrorWidget.builder , crashlytics wiring
9. 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](https://dart.dev/effective dart/design)
[Flutter Performance Best Practices](https://docs.flutter.dev/perf/best practices)
[Riverpod Documentation](https://riverpod.dev/)
[BLoC Library](https://bloclibrary.dev/)
[GoRouter](https://pub.dev/packages/go router)
[Freezed](https://pub.dev/packages/freezed)
Skill: flutter dart code review — comprehensive review checklist
Rules: rules/dart/ — coding style, patterns, security, testing, hooks