Skip to content

Clarify documentation about when Flutter stops rebuilding #38740

@derolf

Description

@derolf

In the best-practies it reads:

The traversal to rebuild all descendents stops when the same instance of the child widget as the previous frame is re-encountered.

People confuse "same" with "equal" vs "identical". So, the question raises whether Flutter is using the operator== or the identical function to determine when to stop rebuilding. Here is the code from framework.dart:

  if (child.widget == newWidget) {
    if (child.slot != newSlot)
      updateSlotForChild(child, newSlot);
    return child;
  }

Obviously, "same instance" in the docs is highly misleading and it should rather read "equal instances". Hence, two non-identical widgets with the same runtime-type and key that are equal with respect to == will stop rebuilding. That's an important aspect for performance optimisations.

For sure, the operator== defaults to identical in Dart, hence overriding operator== for a Widget is required to let the optimisation kick in.

I think it would make sense to clarify that in the docs. (Replace "same" with "equal" and elaborate on the fact.)

Link to Stackoverflow:

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions