use_setters_to_change_properties
The method is used to change a property.
Description
#The analyzer produces this diagnostic when a method is used to set the value of a field, or a function is used to set the value of a top-level variable, and nothing else.
Example
#The following code produces this diagnostic because the method setF
is used to set the value of the field _f
and does no other work:
dart
class C {
int _f = 0;
void setF(int value) => _f = value;
}
Common fixes
#Convert the method to a setter:
dart
class C {
int _f = 0;
set f(int value) => _f = value;
}
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.