avoid-nullable-interpolation
preset: recommended
Warns when an interpolation string contains a nullable value.
Consider checking the value to be non-null before using it in interpolation.
⚙️ Config
Set ignored-invocations
(default is empty) to ignore interpolation strings within specific invocations.
dart_code_metrics:
...
rules:
...
- avoid-nullable-interpolation:
ignored-invocations:
- log
- debugPrint
Example
❌ Bad:
void function(String? value) {
print('$value hello'); // LINT
}
✅ Good:
void function(String? value) {
if (value != null) {
print('$value hello');
}
print('${value != null ? value : ''} hello');
}