Skip to main content

avoid-unassigned-local-variable

effort: 4m
pro+

Warns when a local variable is used but has not yet received a value.

Example

❌ Bad:

int? _value() {
int? val;

// LINT: This local variable is used but has not yet received a value.
// Try assigning a value or using 'null' directly.
print(val);

return val;
}

int? _another() {
int? val;

// LINT: This local variable is used but has not yet received a value.
// Try assigning a value or using 'null' directly.
return val;
}

✅ Good:

int? correct() {
int? val;

val = 1;

return val;
}

int? correct() {
final val = 1;

return val;
}