-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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: