Skip to content
Back to skills

Dart Language

ASecurity

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...

  • 584 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
developmentexpress

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill dart-language --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dart Language?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Dart Language
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-dart-language-d1b75774/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-language-d1b75774)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
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.md1.8 KB
  • eval-1.with-skill.md1.5 KB
  • eval-2.baseline.md2 KB
  • eval-2.with-skill.md1.4 KB
  • eval-3.baseline.md2.3 KB
  • eval-3.with-skill.md1.4 KB
  • trigger-1.md183 B
  • trigger-2.md209 B
  • trigger-3.md196 B
  • trigger-4.md216 B
  • trigger-5.md176 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.