Add assert to Table to check for rows with null children (#61457)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user