Remove _debugWillReattachChildren
assertions from _TableElement
(#34202)
This commit is contained in:
parent
b1a8637028
commit
539f09f801
@ -250,13 +250,9 @@ class _TableElement extends RenderObjectElement {
|
|||||||
|
|
||||||
List<_TableElementRow> _children = const<_TableElementRow>[];
|
List<_TableElementRow> _children = const<_TableElementRow>[];
|
||||||
|
|
||||||
bool _debugWillReattachChildren = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void mount(Element parent, dynamic newSlot) {
|
void mount(Element parent, dynamic newSlot) {
|
||||||
super.mount(parent, newSlot);
|
super.mount(parent, newSlot);
|
||||||
assert(!_debugWillReattachChildren);
|
|
||||||
assert(() { _debugWillReattachChildren = true; return true; }());
|
|
||||||
_children = widget.children.map<_TableElementRow>((TableRow row) {
|
_children = widget.children.map<_TableElementRow>((TableRow row) {
|
||||||
return _TableElementRow(
|
return _TableElementRow(
|
||||||
key: row.key,
|
key: row.key,
|
||||||
@ -266,32 +262,20 @@ class _TableElement extends RenderObjectElement {
|
|||||||
}).toList(growable: false),
|
}).toList(growable: false),
|
||||||
);
|
);
|
||||||
}).toList(growable: false);
|
}).toList(growable: false);
|
||||||
assert(() { _debugWillReattachChildren = false; return true; }());
|
|
||||||
_updateRenderObjectChildren();
|
_updateRenderObjectChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void insertChildRenderObject(RenderObject child, Element slot) {
|
void insertChildRenderObject(RenderObject child, Element slot) {
|
||||||
assert(_debugWillReattachChildren);
|
|
||||||
renderObject.setupParentData(child);
|
renderObject.setupParentData(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void moveChildRenderObject(RenderObject child, dynamic slot) {
|
void moveChildRenderObject(RenderObject child, dynamic slot) {
|
||||||
assert(_debugWillReattachChildren);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void removeChildRenderObject(RenderObject child) {
|
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;
|
final TableCellParentData childParentData = child.parentData;
|
||||||
renderObject.setChild(childParentData.x, childParentData.y, null);
|
renderObject.setChild(childParentData.x, childParentData.y, null);
|
||||||
}
|
}
|
||||||
@ -300,8 +284,6 @@ class _TableElement extends RenderObjectElement {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void update(Table newWidget) {
|
void update(Table newWidget) {
|
||||||
assert(!_debugWillReattachChildren);
|
|
||||||
assert(() { _debugWillReattachChildren = true; return true; }());
|
|
||||||
final Map<LocalKey, List<Element>> oldKeyedRows = <LocalKey, List<Element>>{};
|
final Map<LocalKey, List<Element>> oldKeyedRows = <LocalKey, List<Element>>{};
|
||||||
for (_TableElementRow row in _children) {
|
for (_TableElementRow row in _children) {
|
||||||
if (row.key != null) {
|
if (row.key != null) {
|
||||||
@ -330,7 +312,7 @@ class _TableElement extends RenderObjectElement {
|
|||||||
updateChildren(oldUnkeyedRows.current.children, const <Widget>[], forgottenChildren: _forgottenChildren);
|
updateChildren(oldUnkeyedRows.current.children, const <Widget>[], forgottenChildren: _forgottenChildren);
|
||||||
for (List<Element> oldChildren in oldKeyedRows.values.where((List<Element> list) => !taken.contains(list)))
|
for (List<Element> oldChildren in oldKeyedRows.values.where((List<Element> list) => !taken.contains(list)))
|
||||||
updateChildren(oldChildren, const <Widget>[], forgottenChildren: _forgottenChildren);
|
updateChildren(oldChildren, const <Widget>[], forgottenChildren: _forgottenChildren);
|
||||||
assert(() { _debugWillReattachChildren = false; return true; }());
|
|
||||||
_children = newChildren;
|
_children = newChildren;
|
||||||
_updateRenderObjectChildren();
|
_updateRenderObjectChildren();
|
||||||
_forgottenChildren.clear();
|
_forgottenChildren.clear();
|
||||||
|
@ -19,6 +19,24 @@ class TestStatefulWidgetState extends State<TestStatefulWidget> {
|
|||||||
Widget build(BuildContext context) => Container();
|
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() {
|
void main() {
|
||||||
testWidgets('Table widget - empty', (WidgetTester tester) async {
|
testWidgets('Table widget - empty', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(
|
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
|
// TODO(ianh): Test handling of TableCell object
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user