Skip to content
Back to skills

Dart Best Practices

ASecurity

Yes. The main fixes are: - remove top-level mutable globals - prefer `const` and `final` over `var` - use tear-offs when the lambda only forwards its argument - keep naming consistent with Effective Dart - `await` async work unless fire-and-forget is intentional A good refactor usually looks like this: ```dart class UserFormatter { const UserFormatter(); String formatName(User user) => user.name.trim(); List<String> formatAll(List<User> users) => users.map(formatName).toList(); } ``` Instead ...

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

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-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dart Best Practices?

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

Security grade badge for Dart Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-dart-best-practices-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-best-practices-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
Yes. The main fixes are:

- remove top-level mutable globals
- prefer `const` and `final` over `var`
- use tear-offs when the lambda only forwards its argument
- keep naming consistent with Effective Dart
- `await` async work unless fire-and-forget is intentional

A good refactor usually looks like this:

```dart
class UserFormatter {
  const UserFormatter();

  String formatName(User user) => user.name.trim();

  List<String> formatAll(List<User> users) => users.map(formatName).toList();
}
```

Instead of this:

```dart
var cache = [];

String format(User user) {
  return user.name.trim();
}

List<String> formatAll(List<User> users) {
  var result = [];
  users.forEach((user) {
    result.add(format(user));
  });
  return result;
}
```

Prefer this:

```dart
class UserService {
  UserService();

  final List<String> _cache = <String>[];

  String format(User user) => user.name.trim();

  List<String> formatAll(List<User> users) {
    final result = users.map(format).toList();
    _cache.addAll(result);
    return result;
  }
}
```

Why this is better:

- `_cache` is private and scoped inside a class instead of living as mutable global state.
- `final` makes ownership and mutability clearer than `var`.
- `<String>[]` avoids accidental `dynamic`.
- `users.map(format)` uses a tear-off instead of an unnecessary anonymous lambda.
- expression bodies keep small methods compact and readable.

If the original file has multi-line constructor calls or literals, also add trailing commas:

```dart
final user = User(
  id: id,
  name: name,
);
```

And keep string style consistent:

```dart
final label = 'Ready';
final message = 'Hello, $name';
```

So yes: fix it by encapsulating state, tightening types, preferring `const`/`final`, and replacing pass-through lambdas with tear-offs where possible.

Files in this skill

  • eval-1.baseline.md1.8 KB
  • eval-1.with-skill.md1.8 KB
  • eval-2.baseline.md1.3 KB
  • eval-2.with-skill.md1.7 KB
  • eval-3.baseline.md1.4 KB
  • eval-3.with-skill.md1.2 KB
  • trigger-1.md165 B
  • trigger-2.md159 B
  • trigger-3.md150 B
  • trigger-4.md143 B
  • trigger-5.md158 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.