dart-flutter-patterns

Provides production-ready Dart and Flutter code patterns for state management, navigation, networking, and testing.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill dart-flutter-patterns-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dart-flutter-patterns
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/dart-flutter-patterns
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill dart-flutter-patterns-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Flutter developers often struggle with choosing idiomatic patterns for null safety, state management, navigation, and async handling, leading to runtime crashes, unnecessary rebuilds, and inconsistent architecture across projects. ## Core Features & Use Cases - Null Safety & Immutable State: Patterns for avoiding the bang operator, using Dart 3 sealed classes and pattern matching, and Freezed for boilerplate-free immutable models. - State Management Coverage: Copy-paste-ready implementations for BLoC/Cubit, Riverpod notifiers and derived providers, plus guidance on choosing between them. - Navigation, Networking & Testing: GoRouter with reactive auth guards, Dio interceptors with one-time token refresh retry, and unit/widget/BLoC test examples. - Use Case: When starting a new Flutter feature, consult this Skill to wire up a Riverpod cart notifier with derived total providers, guard routes with GoRouter auth redirects, and write widget tests using ProviderScope overrides. ## Quick Start Ask the AI to show the recommended Flutter pattern for implementing authentication-guarded navigation with GoRouter and a Cubit.

Frequently Asked Questions about dart-flutter-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage state in Flutter with Riverpod?▼

Riverpod state management uses @riverpod annotated providers for async data and Notifier classes for complex mutations. Derived providers can watch other providers to compute values like cart totals, and auto-dispose keeps memory usage bounded.

BLoC vs Riverpod vs Provider for Flutter state management?▼

BLoC/Cubit suits event-driven flows with explicit state transitions and blocTest support, while Riverpod offers compile-safe dependency injection and derived providers. Provider is the simplest option for basic dependency injection and change notification.

How to add auth guards with GoRouter in Flutter?▼

GoRouter auth guards use the redirect callback combined with refreshListenable wired to your auth state stream. The redirect checks authentication status and returns '/login' for unauthenticated users, re-evaluating automatically when auth state changes.

Why does my Flutter app crash after await with BuildContext?▼

Using BuildContext after an await crashes when the widget was unmounted during the async gap. Always check the mounted property before calling context-dependent methods like navigation or ScaffoldMessenger in StatefulWidget async handlers.

Does Dio support automatic token refresh on 401 errors?▼

Dio supports token refresh through an InterceptorsWrapper onError handler that detects 401 responses, attempts a refresh, and retries the original request. A one-time retry flag in requestOptions.extra prevents infinite retry loops.

When should I avoid using the late keyword in Dart?▼

Avoid late when initialization timing is uncertain, since it defers null errors to runtime. It is acceptable only when initialization is guaranteed before first access, such as AnimationController setup in initState; otherwise prefer nullable fields with explicit checks.