Dart Language
ASecurityUse 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
Works with
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-agent-skills-standard)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.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.