
Dart Flutter Patterns
Scaffold Flutter features with idiomatic null-safe Dart, state management, routing, and networking patterns instead of ad-hoc widget spaghetti.
Overview
Dart/Flutter Patterns is an agent skill for the Build phase that supplies production-ready Dart and Flutter patterns for state, navigation, networking, and testing.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill dart-flutter-patternsWhat is this skill?
- Seven concern areas: null safety, immutable state, async composition, widgets, state management, navigation, networking
- State management recipes for BLoC/Cubit, Riverpod (notifiers and derived providers), and Provider
- GoRouter setup with reactive auth guards via refreshListenable
- Dio HTTP client patterns plus WebView and local storage guidance
- Testing guidance for widgets, Cubits, and Riverpod providers
- 7 documented pattern concern areas
- 3 state management frameworks covered: BLoC, Riverpod, Provider
Adoption & trust: 3.3k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are building a Flutter app but keep reinventing null-safe models, routing guards, and state containers differently in every feature.
Who is it for?
Solo developers starting or scaling a Flutter client who want opinionated structure across state, routing, and API layers.
Skip if: Teams on non-Flutter stacks or builders who only need one-off snippets without architecture or test discipline.
When should I use this skill?
Starting a Flutter feature; reviewing Dart code; choosing state management; implementing GoRouter, Dio, WebView, or storage; writing widget/Cubit/Riverpod tests.
What do I get? / Deliverables
You apply consistent, copy-paste-ready patterns for widgets, BLoC/Riverpod/Provider, GoRouter, and Dio so new features match the rest of the codebase.
- Feature-ready widget and state layer snippets
- Navigation and API client wiring aligned to skill patterns
- Test scaffolding for widgets and state containers
Recommended Skills
Journey fit
The skill delivers implementation patterns while you are actively building the mobile client, so Build is the natural primary shelf. Content focuses on widgets, state, navigation, and UI-layer networking—classic frontend/mobile client work within Build.
How it compares
A structured pattern library for Flutter features, not a generic Dart language tutorial or a backend-only API skill.
Common Questions / FAQ
Who is dart-flutter-patterns for?
Indie and solo builders writing Dart and Flutter who need idiomatic architecture for state, navigation, networking, and tests.
When should I use dart-flutter-patterns?
During Build when starting a feature, choosing BLoC vs Riverpod vs Provider, wiring GoRouter auth guards, or reviewing Flutter UI and Cubit tests.
Is dart-flutter-patterns safe to install?
Treat it as code-generation and dependency guidance—review the Security Audits panel on this page and vet third-party packages before adding them to pubspec.
SKILL.md
READMESKILL.md - Dart Flutter Patterns
# 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 ```dart // Sealed state — prevents impossible states sealed class AsyncState<T> {} final class Loading<T> extends AsyncState<T> {} final class Success<T> extends AsyncState<T> { final T data; const Success(this.data); } final class Failure<T> extends AsyncState<T> { final Object error; const Failure(this.error); } // GoRouter with reactive auth redirect final router = GoRouter( refreshListenable: GoRouterRefreshStream(authCubit.stream), redirect: (context, state) { final authed = context.read<AuthCubit>().state is AuthAuthenticated; if (!authed && !state.matchedLocation.startsWith('/login')) return '/login'; return null; }, routes: [...], ); // Riverpod derived provider with safe firstWhereOrNull @riverpod double cartTotal(Ref ref) { final cart = ref.watch(cartNotifierProvider); final products = ref.watch(productsProvider).valueOrNull ?? []; return cart.fold(0.0, (total, item) { final product = products.firstWhereOrNull((p) => p.id == item.productId); return total + (product?.price ?? 0) * item.quantity; }); } ``` --- 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 ```dart // BAD — crashes at runtime if null final name = user!.name; // GOOD — provide fallback final name = user?.name ?? 'Unknown'; // GOOD — Dart 3 pattern matching (preferred for complex cases) final display = switch (user) { User(:final name, :final email) => '$name <$email>', null => 'Guest', }; // GOOD — guard early return String getUserName(User? user) { if (user == null) return 'Unknown'; return user.name; // promoted to non-null after check } ``` ### Avoid `late` Overuse ```dart // BAD — defers null error to runtime late String userId; // GOOD — nullable with explicit initialization String? userId; // OK — use late only when initialization is guaranteed before first access // (e.g., in initState() before any widget interaction) late final AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 300)