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

This commit is contained in:
Todd Volkert
2020-07-14 12:20:22 -07:00
committed by GitHub
parent 06a35b3322
commit 74f3e6dd63
2 changed files with 33 additions and 0 deletions

View File

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

View File

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