Skip to main content

avoid-unused-after-null-check

added in: 1.13.0

Warns when a variable is checked for non-nullable value, but is not used within the condition or then branch.

info

This rule triggers only for cases when there is a potential place for an unused variable (e.g. matching type or invocation target).

Example

❌ Bad:

void fn(String value) {
final String? myNullableValue = 'hello';
if (myNullableValue != null) {
print(value); // LINT
}
}

✅ Good:

void fn(String value) {
final String? myNullableValue = 'hello';
if (myNullableValue != null) {
print(myNullableValue);
}
}