@@ -1031,12 +1031,14 @@ class _RenderTheater extends RenderBox with ContainerRenderObjectMixin<RenderBox
1031
1031
void _addDeferredChild (_RenderDeferredLayoutBox child) {
1032
1032
assert (! _skipMarkNeedsLayout);
1033
1033
_skipMarkNeedsLayout = true ;
1034
-
1035
1034
adoptChild (child);
1036
- // When child has never been laid out before, mark its layout surrogate as
1037
- // needing layout so it's reachable via tree walk.
1038
- child._layoutSurrogate.markNeedsLayout ();
1039
1035
_skipMarkNeedsLayout = false ;
1036
+
1037
+ // After adding `child` to the render tree, we want to make sure it will be
1038
+ // laid out in the same frame. This is done by calling markNeedsLayout on the
1039
+ // layout surrgate. This ensures `child` is reachable via tree walk (see
1040
+ // _RenderLayoutSurrogateProxyBox.performLayout).
1041
+ child._layoutSurrogate.markNeedsLayout ();
1040
1042
}
1041
1043
1042
1044
void _removeDeferredChild (_RenderDeferredLayoutBox child) {
@@ -1048,10 +1050,9 @@ class _RenderTheater extends RenderBox with ContainerRenderObjectMixin<RenderBox
1048
1050
1049
1051
@override
1050
1052
void markNeedsLayout () {
1051
- if (_skipMarkNeedsLayout) {
1052
- return ;
1053
+ if (! _skipMarkNeedsLayout) {
1054
+ super . markNeedsLayout () ;
1053
1055
}
1054
- super .markNeedsLayout ();
1055
1056
}
1056
1057
1057
1058
RenderBox ? get _firstOnstageChild {
@@ -2088,7 +2089,7 @@ final class _RenderDeferredLayoutBox extends RenderProxyBox with _RenderTheaterM
2088
2089
RenderObject ? get debugLayoutParent => _layoutSurrogate;
2089
2090
2090
2091
void layoutByLayoutSurrogate () {
2091
- assert (! _parentDoingLayout );
2092
+ assert (! _theaterDoingThisLayout );
2092
2093
final _RenderTheater ? theater = parent as _RenderTheater ? ;
2093
2094
if (theater == null || ! attached) {
2094
2095
assert (false , '$this is not attached to parent' );
@@ -2097,25 +2098,26 @@ final class _RenderDeferredLayoutBox extends RenderProxyBox with _RenderTheaterM
2097
2098
super .layout (BoxConstraints .tight (theater.constraints.biggest));
2098
2099
}
2099
2100
2100
- bool _parentDoingLayout = false ;
2101
+ bool _theaterDoingThisLayout = false ;
2101
2102
@override
2102
2103
void layout (Constraints constraints, { bool parentUsesSize = false }) {
2103
2104
assert (_needsLayout == debugNeedsLayout);
2104
2105
// Only _RenderTheater calls this implementation.
2105
2106
assert (parent != null );
2106
2107
final bool scheduleDeferredLayout = _needsLayout || this .constraints != constraints;
2107
- assert (! _parentDoingLayout );
2108
- _parentDoingLayout = true ;
2108
+ assert (! _theaterDoingThisLayout );
2109
+ _theaterDoingThisLayout = true ;
2109
2110
super .layout (constraints, parentUsesSize: parentUsesSize);
2110
- assert (_parentDoingLayout );
2111
- _parentDoingLayout = false ;
2111
+ assert (_theaterDoingThisLayout );
2112
+ _theaterDoingThisLayout = false ;
2112
2113
_needsLayout = false ;
2113
2114
assert (! debugNeedsLayout);
2114
2115
if (scheduleDeferredLayout) {
2115
2116
final _RenderTheater parent = this .parent! as _RenderTheater ;
2116
2117
// Invoking markNeedsLayout as a layout callback allows this node to be
2117
- // merged back to the `PipelineOwner` if it's not already dirty. Otherwise
2118
- // this may cause some dirty descendants to performLayout a second time.
2118
+ // merged back to the `PipelineOwner`'s dirty list in the right order, if
2119
+ // it's not already dirty. Otherwise this may cause some dirty descendants
2120
+ // to performLayout a second time.
2119
2121
parent.invokeLayoutCallback ((BoxConstraints constraints) { markNeedsLayout (); });
2120
2122
}
2121
2123
}
@@ -2129,7 +2131,7 @@ final class _RenderDeferredLayoutBox extends RenderProxyBox with _RenderTheaterM
2129
2131
@override
2130
2132
void performLayout () {
2131
2133
assert (! _debugMutationsLocked);
2132
- if (_parentDoingLayout ) {
2134
+ if (_theaterDoingThisLayout ) {
2133
2135
_needsLayout = false ;
2134
2136
return ;
2135
2137
}
0 commit comments