Dart Language
ASecurityMake 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...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill dart-language --agent claude-codeAre you the author of Dart Language?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-language-d1b75774)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.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.