-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
OverlayPortal.childLayoutBuilder
should rebuild when OverlayPortal
rebuilds.
#165331
OverlayPortal.childLayoutBuilder
should rebuild when OverlayPortal
rebuilds.
#165331
Conversation
…rebuilds. The builder callback can capture free variables. So the it must be re-evaluated every time `OverlayPortal` rebuilds.
} | ||
|
||
@override | ||
void ensureFrameCallbacksRegistered() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can create a different method to call the ensureFrameCallbacksRegistered
..dispose(), | ||
); | ||
|
||
Widget builder(BuildContext _, OverlayChildLayoutInfo _) => ColoredBox(color: color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this code is the correct usage of builder. In a widget build method, it will be developer's job to ensure the widget rebuild if it reference a state outside of the build method. Either turn that into changenotifier and use ChangeNotifierBuilder, or use inherited widget to do dependsOnInheritedWidget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's true. In a Builder
/ StatefulBuilder
/ LayoutBuilder
the developer should be allowed to capture free variables in the callback. The framework should rebuild the entire widget tree if the root is dirty (unless it hits a cached widget) otherwise every builder
callback will have to be closed functions because they may use variables defined in its parent widget's State
. Otherwise the syntax will be way too verbose, and builder widgets will be a pain to use / debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this makes sense consider that is true for other builder type widget. SGTM then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
..dispose(), | ||
); | ||
|
||
Widget builder(BuildContext _, OverlayChildLayoutInfo _) => ColoredBox(color: color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this makes sense consider that is true for other builder type widget. SGTM then
@@ -2615,7 +2615,7 @@ class _OverlayChildLayoutBuilder extends AbstractLayoutBuilder<OverlayChildLayou | |||
) => _RenderLayoutBuilder(); | |||
|
|||
@override | |||
bool updateShouldRebuild(_OverlayChildLayoutBuilder oldWidget) => oldWidget.builder != builder; | |||
bool updateShouldRebuild(_OverlayChildLayoutBuilder oldWidget) => true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as default implementation, I think we can remove this override
…rlayPortal` rebuilds. (flutter/flutter#165331)
The builder callback can capture free variables. So it must be re-evaluated every time
OverlayPortal
rebuilds.Also defining the builder callback as a method in the State class seems to be a common pattern. So the
oldWidget.builder != builder
check may prevent necessary rebuilds when that's the case.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.