New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify documentation about when Flutter stops rebuilding #38740
Comments
Another place in the documentation where this is unclear is in the documentation of the StatelessWidget class. It says It is unclear what "configuration" means here, it seems to be the arguments to the widget's constructor. It is unclear whether the "first time the widget is inserted in the tree" means the first time a widget of this type is inserted at this location in the tree, or the first time this widget instance is inserted in the tree. Neither seems to be correct. When the parent rebuilds, and an identical, an equal, or a constant (identical) widget instance appears here, the build method won't be (necessarily) called. If the parent build method introduces a new instance of the same widget, even with the same constructor arguments, its build method will be called unless operator== says it is equal to the previous instance. |
Fixes flutter#112676. Fixes flutter#97015. Fixes flutter#62107. Fixes flutter#38740. Fixes flutter#31911. Fixes flutter#29958. Fixes flutter#18108. Fixes flutter#17160. Fixes flutter#14243. Fixes flutter#3354.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
In the best-practies it reads:
People confuse "same" with "equal" vs "identical". So, the question raises whether Flutter is using the
operator==
or theidentical
function to determine when to stop rebuilding. Here is the code fromframework.dart
: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
andkey
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 overridingoperator==
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:
The text was updated successfully, but these errors were encountered: