Skip to content

Commit c44dd17

Browse files
committed
Always reset parentData when dropping children
Previously, we'd leave the old values in the parent data if the types matches, but not all render objects would reset these values during layout. For example, RenderProxyBox doesn't set the position field because it doesn't read the position field. However, leaving the old data there violates the invariants of the box protocol and can cause trouble (e.g., localToGlobal giving the wrong result). Fixes #1939
1 parent 7925e06 commit c44dd17

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/flutter/lib/src/rendering/object.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
464464
assert(child.parentData != null);
465465
child._cleanRelayoutSubtreeRoot();
466466
child.parentData.detach();
467+
child.parentData = null;
467468
super.dropChild(child);
468469
markNeedsLayout();
469470
_markNeedsCompositingBitsUpdate();

packages/unit/test/rendering/box_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,25 @@ void main() {
7373
expect(coloredBox.size.width, equals(780.0));
7474
expect(coloredBox.size.height, equals(580.0));
7575
});
76+
77+
test("reparenting should clear position", () {
78+
RenderDecoratedBox coloredBox = new RenderDecoratedBox(
79+
decoration: new BoxDecoration());
80+
RenderPadding paddedBox = new RenderPadding(
81+
child: coloredBox, padding: const EdgeDims.all(10.0));
82+
83+
layout(paddedBox);
84+
85+
BoxParentData parentData = coloredBox.parentData;
86+
expect(parentData.position.x, isNot(equals(0.0)));
87+
88+
paddedBox.child = null;
89+
RenderConstrainedBox constraintedBox = new RenderConstrainedBox(
90+
child: coloredBox, additionalConstraints: const BoxConstraints());
91+
92+
layout(constraintedBox);
93+
94+
parentData = coloredBox.parentData;
95+
expect(parentData.position.x, equals(0.0));
96+
});
7697
}

0 commit comments

Comments
 (0)