Skip to content

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

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 updateRenderObject it 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.

Violating
@override
RenderDot createRenderObject(BuildContext context) =>
RenderDot(color: color, radius: radius);
@override
void updateRenderObject(BuildContext context, RenderDot renderObject) {
renderObject.color = color;
}
Corrected
@override
void updateRenderObject(BuildContext context, RenderDot renderObject) {
renderObject
..color = color
..radius = radius;
}

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.

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.