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
This commit is contained in:
yim
2023-02-18 02:29:02 +08:00
committed by GitHub
parent 674254c036
commit c4d40cc152
2 changed files with 25 additions and 2 deletions

View File

@@ -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;

View File

@@ -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 {