Dart Language
ASecurityThe safer approach is to stop force-unwrapping and make the null case explicit in your control flow. In modern Dart, `!` should be the exception, not the default. Prefer one of these patterns instead: 1. Guard early with an `if` ```dart void greet(String? name) { if (name == null) { print('Missing name'); return; } print('Hello, $name'); } ``` 2. Use `??` for a fallback value ```dart String displayName(String? name) => name ?? 'Guest'; ``` 3. Use `?.` when accessing members on a nullable valu...
- 584 stars
- 0 votes
- 0 copies
- 4 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-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-41cdbec4)The safer approach is to stop force-unwrapping and make the null case explicit in your control flow.
In modern Dart, `!` should be the exception, not the default. Prefer one of these patterns instead:
1. Guard early with an `if`
```dart
void greet(String? name) {
if (name == null) {
print('Missing name');
return;
}
print('Hello, $name');
}
```
2. Use `??` for a fallback value
```dart
String displayName(String? name) => name ?? 'Guest';
```
3. Use `?.` when accessing members on a nullable value
```dart
int nameLength(String? name) => name?.length ?? 0;
```
4. Narrow once, then use the non-null local value
```dart
void sendEmail(String? email) {
if (email case final value?) {
print('Sending to $value');
return;
}
print('No email provided');
}
```
Why this is better than repeated `!`:
- It prevents runtime null-assertion crashes.
- It documents what should happen when the value is absent.
- It keeps the code aligned with Dart’s null-safety model instead of bypassing it.
If you find yourself writing `value!` everywhere, that usually means one of two things:
- the variable should not be nullable in the first place, so tighten the type to `String`
- the null case is real, so handle it once near the boundary and pass a non-null value deeper into the code
In short: prefer `if`, `?.`, `??`, and pattern-based null checks; only use `!` when you can prove non-nullness at that exact point.
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.