Pattern: Missing use of final
for variable
Issue: -
Declaring variables as final when possible is a good practice because it helps avoid accidental reassignments and allows the compiler to do optimizations.
Example of incorrect code:
void badMethod() {
var label = 'hola mundo! badMethod'; // LINT
print(label);
}
Example of correct code:
void goodMethod() {
final label = 'hola mundo! goodMethod';
print(label);
}
Example of correct code:
void mutableCase() {
var label = 'hola mundo! mutableCase';
print(label);
label = 'hello world';
print(label);
}