diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 8d278b6e6e..070398f93d 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -1275,9 +1275,6 @@ abstract class RenderObjectElement extends Buildab super.mount(parent, newSlot); assert(_slot == newSlot); attachRenderObject(newSlot); - ParentDataElement parentDataElement = _findAncestorParentDataElement(); - if (parentDataElement != null) - updateParentData(parentDataElement.widget); _dirty = false; } @@ -1491,6 +1488,9 @@ abstract class RenderObjectElement extends Buildab _slot = newSlot; _ancestorRenderObjectElement = _findAncestorRenderObjectElement(); _ancestorRenderObjectElement?.insertChildRenderObject(renderObject, newSlot); + ParentDataElement parentDataElement = _findAncestorParentDataElement(); + if (parentDataElement != null) + updateParentData(parentDataElement.widget); } void detachRenderObject() { diff --git a/packages/unit/test/widget/parent_data_test.dart b/packages/unit/test/widget/parent_data_test.dart index bc5eb2e922..59af8bfe87 100644 --- a/packages/unit/test/widget/parent_data_test.dart +++ b/packages/unit/test/widget/parent_data_test.dart @@ -284,4 +284,55 @@ void main() { checkTree(tester, []); }); }); + + test('ParentDataWidget interacts with global keys', () { + testWidgets((WidgetTester tester) { + GlobalKey key = new GlobalKey(); + + tester.pumpWidget( + new Stack([ + new Positioned( + top: 10.0, + left: 10.0, + child: new DecoratedBox(key: key, decoration: kBoxDecorationA) + ) + ]) + ); + + checkTree(tester, [ + new TestParentData(top: 10.0, left: 10.0), + ]); + + tester.pumpWidget( + new Stack([ + new Positioned( + top: 10.0, + left: 10.0, + child: new DecoratedBox( + decoration: kBoxDecorationB, + child: new DecoratedBox(key: key, decoration: kBoxDecorationA) + ) + ) + ]) + ); + + checkTree(tester, [ + new TestParentData(top: 10.0, left: 10.0), + ]); + + tester.pumpWidget( + new Stack([ + new Positioned( + top: 10.0, + left: 10.0, + child: new DecoratedBox(key: key, decoration: kBoxDecorationA) + ) + ]) + ); + + checkTree(tester, [ + new TestParentData(top: 10.0, left: 10.0), + ]); + }); + }); }