Dart Best Practices
ASecurityYes. 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
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-best-practices --agent claude-codeAre you the author of Dart Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-best-practices-agent-skills-standard)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.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.