Unverified Commit 539f09f8 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove `_debugWillReattachChildren` assertions from `_TableElement` (#34202)

parent b1a86370
......@@ -250,13 +250,9 @@ class _TableElement extends RenderObjectElement {
List<_TableElementRow> _children = const<_TableElementRow>[];
bool _debugWillReattachChildren = false;
@override
void mount(Element parent, dynamic newSlot) {
super.mount(parent, newSlot);
assert(!_debugWillReattachChildren);
assert(() { _debugWillReattachChildren = true; return true; }());
_children = widget.children.map<_TableElementRow>((TableRow row) {
return _TableElementRow(
key: row.key,
......@@ -266,32 +262,20 @@ class _TableElement extends RenderObjectElement {
}).toList(growable: false),
);
}).toList(growable: false);
assert(() { _debugWillReattachChildren = false; return true; }());
_updateRenderObjectChildren();
}
@override
void insertChildRenderObject(RenderObject child, Element slot) {
assert(_debugWillReattachChildren);
renderObject.setupParentData(child);
}
@override
void moveChildRenderObject(RenderObject child, dynamic slot) {
assert(_debugWillReattachChildren);
}
@override
void removeChildRenderObject(RenderObject child) {
assert(() {
if (_debugWillReattachChildren)
return true;
for (Element forgottenChild in _forgottenChildren) {
if (forgottenChild.renderObject == child)
return true;
}
return false;
}());
final TableCellParentData childParentData = child.parentData;
renderObject.setChild(childParentData.x, childParentData.y, null);
}
......@@ -300,8 +284,6 @@ class _TableElement extends RenderObjectElement {
@override
void update(Table newWidget) {
assert(!_debugWillReattachChildren);
assert(() { _debugWillReattachChildren = true; return true; }());
final Map<LocalKey, List<Element>> oldKeyedRows = <LocalKey, List<Element>>{};
for (_TableElementRow row in _children) {
if (row.key != null) {
......@@ -330,7 +312,7 @@ class _TableElement extends RenderObjectElement {
updateChildren(oldUnkeyedRows.current.children, const <Widget>[], forgottenChildren: _forgottenChildren);
for (List<Element> oldChildren in oldKeyedRows.values.where((List<Element> list) => !taken.contains(list)))
updateChildren(oldChildren, const <Widget>[], forgottenChildren: _forgottenChildren);
assert(() { _debugWillReattachChildren = false; return true; }());
_children = newChildren;
_updateRenderObjectChildren();
_forgottenChildren.clear();
......
......@@ -19,6 +19,24 @@ class TestStatefulWidgetState extends State<TestStatefulWidget> {
Widget build(BuildContext context) => Container();
}
class TestChildWidget extends StatefulWidget {
const TestChildWidget({ Key key }) : super(key: key);
@override
TestChildState createState() => TestChildState();
}
class TestChildState extends State<TestChildWidget> {
bool toggle = true;
void toggleMe() {
setState(() { toggle = !toggle; });
}
@override
Widget build(BuildContext context) => toggle ? const SizedBox() : const Text('CRASHHH');
}
void main() {
testWidgets('Table widget - empty', (WidgetTester tester) async {
await tester.pumpWidget(
......@@ -855,5 +873,32 @@ void main() {
);
});
// Regression test for https://github.com/flutter/flutter/issues/31473.
testWidgets(
'Does not crash if a child RenderObject is replaced by another RenderObject of a different type',
(WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Table(children: const <TableRow>[TableRow(children: <Widget>[TestChildWidget()])]),
),
);
expect(find.text('CRASHHH'), findsNothing);
final TestChildState state = tester.state(find.byType(TestChildWidget));
state.toggleMe();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Table(children: const <TableRow>[TableRow(children: <Widget>[TestChildWidget()])]),
),
);
// Should not crash.
expect(find.text('CRASHHH'), findsOneWidget);
}
);
// TODO(ianh): Test handling of TableCell object
}
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