Skip to content
Back to skills

Dart Language

ASecurity

Use a Dart record. For a lightweight “success value + error message” return without introducing a custom class, the modern Dart 3 approach is to return a record and destructure it at the call site. Prefer named fields when the meaning of each value matters. Example: ```dart (String? data, String? error) parseUsername(String input) { if (input.trim().isEmpty) { return (data: null, error: 'Username cannot be empty'); } return (data: input.trim(), error: null); } void main() { final (:data, :err...

  • 584 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
developmentapi

Works with

  • api

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-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-language-agent-skills-standard)

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
Use a Dart record.

For a lightweight “success value + error message” return without introducing a custom class, the modern Dart 3 approach is to return a record and destructure it at the call site. Prefer named fields when the meaning of each value matters.

Example:

```dart
(String? data, String? error) parseUsername(String input) {
  if (input.trim().isEmpty) {
    return (data: null, error: 'Username cannot be empty');
  }

  return (data: input.trim(), error: null);
}

void main() {
  final (:data, :error) = parseUsername('alice');

  if (error != null) {
    print(error);
    return;
  }

  print('Parsed user: $data');
}
```

Why this is the idiomatic choice:

- Records are built into Dart 3, so they are ideal for simple multi-value returns.
- Named fields make the API easier to read than positional values like `(String?, String?)`.
- Destructuring keeps usage concise and avoids repetitive indexing or temporary variables.

A useful rule of thumb:

- Use a record when the return shape is small and local.
- Use a custom type when the result has behavior, many fields, or is reused across the codebase.

If you want to make the intent even clearer, you can define a typedef:

```dart
typedef ParseResult = ({String? data, String? error});

ParseResult parseUsername(String input) {
  if (input.trim().isEmpty) {
    return (data: null, error: 'Username cannot be empty');
  }

  return (data: input.trim(), error: null);
}
```

That gives you the convenience of records while keeping the return contract self-documenting.

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.