Unverified Commit 74f3e6dd authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Add assert to Table to check for rows with null children (#61457)

parent 06a35b33
......@@ -113,6 +113,15 @@ class Table extends RenderObjectWidget {
}) : assert(children != null),
assert(defaultColumnWidth != null),
assert(defaultVerticalAlignment != null),
assert(() {
if (children.any((TableRow row) => row.children == null)) {
throw FlutterError(
'One of the rows of the table had null children.\n'
'The children property of TableRow must not be null.'
);
}
return true;
}()),
assert(() {
if (children.any((TableRow row) => row.children.any((Widget cell) => cell == null))) {
throw FlutterError(
......
......@@ -956,5 +956,29 @@ void main() {
},
);
testWidgets(
'Table widget requires all TableRows to have non-null children',
(WidgetTester tester) async {
FlutterError error;
try {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Table(
children: const <TableRow>[
TableRow(children: <Widget>[Text('Some Text')]),
TableRow(),
],
),
),
);
} on FlutterError catch (e) {
error = e;
} finally {
expect(error, isNotNull);
expect(error.toStringDeep(), contains('The children property of TableRow must not be null.'));
}
});
// 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