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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user