Skip to main content

avoid-unused-after-null-check

added in: 1.13.0
Pro+

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';
// LINT: This variable is checked for non-nullable value, but is not used within the condition or then branch. Try referencing it or removing the check.
if (myNullableValue != null) {
print(value);
}
}

✅ Good:

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