Skip to main content

avoid-nullable-interpolation

added in: 1.8.0
⚙️

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 none) 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');
}