Leverages modern Dart 3+ language features including pattern matching, switch expressions, records, and sealed class hierarchies for expressive, type-safe Flutter code.
Scanned 9/7/2026
Install to Claude Code
npx -y skills add smicolon/ai-kit --skill dart-modern-patterns --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Dart Modern Patterns?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/smicolon-dart-modern-patterns)More formats (shields.io, HTML) on the badges page.
---
name: dart-modern-patterns
description: Leverages modern Dart 3+ language features including pattern matching, switch expressions, records, and sealed class hierarchies for expressive, type-safe Flutter code.
version: 1.0.0
---
# Modern Dart 3+ Patterns
Idiomatic Dart 3 features to write concise, safe, and expressive Flutter code.
## 1. Records (Anonymous Typed Tuples)
Return multiple values without creating boilerplate data classes:
```dart
// Function returning a Record with positional and named fields
(String name, int age, {bool isActive}) getUserSummary() {
return ('Alice', 30, isActive: true);
}
// Destructuring records
final (name, age, isActive: active) = getUserSummary();
```
---
## 2. Pattern Matching & Switch Expressions
Use switch expressions for exhaustive state mapping in UI:
```dart
// Switch expression returning a Widget directly
Widget buildStateWidget(AsyncValue<UserData> state) {
return switch (state) {
AsyncData(:final value) => UserProfileView(user: value),
AsyncError(:final error) => ErrorBanner(message: error.toString()),
AsyncLoading() => const CircularProgressIndicator(),
};
}
```
### Relational & Logical Patterns
```dart
String getDiscountLabel(int points) => switch (points) {
>= 1000 => 'VIP (30% off)',
>= 500 && < 1000 => 'Gold (20% off)',
> 0 => 'Standard (10% off)',
_ => 'No discount',
};
```
---
## 3. Sealed Classes for Finite State Machines
`sealed` classes ensure exhaustive compile-time checking:
```dart
sealed class AuthState {
const AuthState();
}
class AuthInitial extends AuthState {
const AuthInitial();
}
class Authenticated extends AuthState {
final User user;
const Authenticated(this.user);
}
class AuthError extends AuthState {
final String message;
const AuthError(this.message);
}
// Compiler errors if any AuthState subtype is unhandled:
String getGreeting(AuthState state) => switch (state) {
AuthInitial() => 'Please sign in',
Authenticated(:final user) => 'Welcome back, ${user.name}!',
AuthError(:final message) => 'Error: $message',
};
```
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!