Unverified Commit be238859 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `TableRow` with no children throws unnamed assertion (#123770)

Fix `TableRow` with no children throws unnamed assertion
parent 6a574ac0
...@@ -144,6 +144,12 @@ class Table extends RenderObjectWidget { ...@@ -144,6 +144,12 @@ class Table extends RenderObjectWidget {
'Otherwise, the table will contain holes.', 'Otherwise, the table will contain holes.',
); );
} }
if (children.any((TableRow row) => row.children.isEmpty)) {
throw FlutterError(
'One or more TableRow have no children.\n'
'Every TableRow in a Table must have at least one child, so there is no empty row. ',
);
}
} }
return true; return true;
}()), }()),
......
...@@ -45,6 +45,7 @@ void main() { ...@@ -45,6 +45,7 @@ void main() {
), ),
); );
}); });
testWidgets('Table widget - control test', (WidgetTester tester) async { testWidgets('Table widget - control test', (WidgetTester tester) async {
Future<void> run(TextDirection textDirection) async { Future<void> run(TextDirection textDirection) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -1033,5 +1034,50 @@ void main() { ...@@ -1033,5 +1034,50 @@ void main() {
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
}); });
testWidgets('TableRow with no children throws an error message', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/119541.
String result = 'no exception';
// Test TableRow with children.
try {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: Table(
children: const <TableRow>[
TableRow(
children: <Widget>[
Text('A'),
],
),
],
),
));
} on FlutterError catch (e) {
result = e.toString();
}
expect(result, 'no exception');
// Test TableRow with no children.
try {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: Table(
children: const <TableRow>[
TableRow(),
],
),
));
} on FlutterError catch (e) {
result = e.toString();
}
expect(
result,
'One or more TableRow have no children.\n'
'Every TableRow in a Table must have at least one child, so there is no empty row.',
);
});
// TODO(ianh): Test handling of TableCell object // 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