Unverified Commit c4d40cc1 authored by yim's avatar yim Committed by GitHub

Modify the updateChildren method deep copy _children (#120773)

* Modify the updateChildren method deep copy _children

* add test

* fix some small nits

* Simplified newChildren declaration in updateChildren
parent 674254c0
......@@ -5944,8 +5944,7 @@ abstract class RenderObjectElement extends Element {
int newChildrenBottom = newWidgets.length - 1;
int oldChildrenBottom = oldChildren.length - 1;
final List<Element> newChildren = oldChildren.length == newWidgets.length ?
oldChildren : List<Element>.filled(newWidgets.length, _NullElement.instance);
final List<Element> newChildren = List<Element>.filled(newWidgets.length, _NullElement.instance);
Element? previousChild;
......
......@@ -1753,6 +1753,30 @@ The findRenderObject() method was called for the following element:
child.dependOnInheritedElement(ancestor);
expect(child.doesDependOnInheritedElement(ancestor), isTrue);
});
testWidgets(
'MultiChildRenderObjectElement.updateChildren test',
(WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/120762.
final GlobalKey globalKey = GlobalKey();
await tester.pumpWidget(Column(
children: <Widget>[
const SizedBox(),
SizedBox(key: globalKey),
const SizedBox(),
],
));
expect(tester.takeException(), isNull);
await tester.pumpWidget(Column(
children: <Widget>[
const SizedBox(),
const SizedBox(),
SizedBox(child: SizedBox(key: globalKey)),
],
));
expect(tester.takeException(), isNull);
});
}
class _TestInheritedElement extends InheritedElement {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment