render_object_setter_without_equality_check
Reports a render object setter that marks the object for layout or paint without first checking that the value changed. Return early when the new value equals the old one.
- Tier
- advisory
- Scope
- Flutter
- Lowest preset
- strict
- Fix
- none
What it reports
Section titled “What it reports”A setter of a class that extends Flutter’s RenderObject, which assigns a field and calls a markNeeds… method of the render object itself, such as markNeedsLayout or markNeedsPaint, without first asking whether the new value differs. The violation is on the setter’s name.
The call is guarded, and not reported, when it stands:
- inside an
ifwhose condition reads both the parameter and a field the setter assigns; or - after an
ifstatement of the body that reads both and leaves the setter.
A comparison inside a called method does not count.
The rule reports nothing in a package that does not use Flutter.
A widget gives its render object every property on each rebuild. A setter that marks without comparing makes every rebuild with the same value cost a layout or a paint.
Example
Section titled “Example”set color(Color value) { _color = value; markNeedsPaint();}set color(Color value) { if (value == _color) return; _color = value; markNeedsPaint();}Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why this place is fine.// ignore: render_object_setter_without_equality_check// ignore_for_file: assay/render_object_setter_without_equality_check silences it in a whole file, and the prefixed // ignore: assay/render_object_setter_without_equality_check works too. See Suppressions.