assignment_to_final
'{0}' can't be used as a setter because it's final.
Description
#The analyzer produces this diagnostic when it finds an invocation of a setter, but there's no setter because the field with the same name was declared to be final
or const
.
Example
#The following code produces this diagnostic because v
is final:
dart
class C {
final v = 0;
}
f(C c) {
c.v = 1;
}
Common fixes
#If you need to be able to set the value of the field, then remove the modifier final
from the field:
dart
class C {
int v = 0;
}
f(C c) {
c.v = 1;
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.