update_render_object_misses_property
Reports a property that a render object widget sets in createRenderObject but never in updateRenderObject. Set it in both.
- Tier
- advisory
- Scope
- Flutter
- Lowest preset
- recommended
- Fix
- none
What it reports
Section titled “What it reports”A property that a class extending Flutter’s RenderObjectWidget gives its render object in createRenderObject, and never in updateRenderObject. The violation covers the argument or the assignment.
In createRenderObject, a property is given by:
- a named argument of the render object’s constructor;
- an assignment in a cascade on it;
- an assignment to a property of a local variable that starts as the render object.
It counts where the render object has a setter of that name, and where the value reads the widget or the context.
updateRenderObject gives a property when it assigns it on its render object parameter: directly, in a cascade, through a cast or through a local variable.
- Where it hands the render object to a call, or calls the
updateRenderObjectit inherits, nothing is reported. - Where the class declares no
updateRenderObject, every property counts as never given, unless a class of the project it extends declares one.
The rule is silent in a package that does not use Flutter.
When the widget is rebuilt with a new value, Flutter calls updateRenderObject with the render object it keeps. A property set only at creation keeps its first value, and the screen does not change.
Example
Section titled “Example”@overrideRenderDot createRenderObject(BuildContext context) => RenderDot(color: color, radius: radius);
@overridevoid updateRenderObject(BuildContext context, RenderDot renderObject) { renderObject.color = color;}@overridevoid updateRenderObject(BuildContext context, RenderDot renderObject) { renderObject ..color = color ..radius = radius;}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: assay/update_render_object_misses_property// ignore_for_file: assay/update_render_object_misses_property silences it in a whole file, and // ignore: update_render_object_misses_property without the prefix works too. See Suppressions.