Make the base type a `sealed class`, then switch on it using pattern matching. In Dart, `sealed` tells the compiler that all subclasses must be known within the same library. That lets a `switch` become exhaustiveness-checked: if you forget one subtype, the compiler can flag it. Example: ```dart sealed class Result {} final class Success extends Result { const Success(this.value); final String value; } final class Failure extends Result { const Failure(this.message); final String message; } S...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill dart-language --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Dart Language?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-language-d1b75774)More formats (shields.io, HTML) on the badges page.
Make the base type a `sealed class`, then switch on it using pattern matching.
In Dart, `sealed` tells the compiler that all subclasses must be known within the same library. That lets a `switch` become exhaustiveness-checked: if you forget one subtype, the compiler can flag it.
Example:
```dart
sealed class Result {}
final class Success extends Result {
const Success(this.value);
final String value;
}
final class Failure extends Result {
const Failure(this.message);
final String message;
}
String describe(Result result) => switch (result) {
Success(value: final value) => 'Success: $value',
Failure(message: final message) => 'Failure: $message',
};
```
Why this works:
- `sealed class Result` restricts subclassing to the same library.
- The compiler knows the full set of possible subtypes.
- A `switch` expression or `switch` statement over `Result` must cover all cases.
If you later add another subtype, for example:
```dart
final class Loading extends Result {
const Loading();
}
```
then the existing switch is no longer exhaustive, and Dart will force you to handle `Loading` too. That is exactly the compiler protection you want.
This is the modern Dart 3 pattern for domain states:
- `sealed class` for closed hierarchies
- pattern matching in `switch`
- subtype field destructuring directly in each case
That combination gives you safer refactors and removes the need for fragile `if (result is Success)` chains.
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!