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 valu...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill dart-language --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Dart Language?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-dart-language-41cdbec4)More formats (shields.io, HTML) on the badges page.
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.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!