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

Fix `TableRow` with no children throws unnamed assertion
This commit is contained in:
Taha Tesser 2023-03-31 01:26:51 +03:00 committed by GitHub
parent 6a574ac00b
commit be2388595e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View file

@ -144,6 +144,12 @@ class Table extends RenderObjectWidget {
'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;
}()),

View file

@ -45,6 +45,7 @@ void main() {
),
);
});
testWidgets('Table widget - control test', (WidgetTester tester) async {
Future<void> run(TextDirection textDirection) async {
await tester.pumpWidget(
@ -1033,5 +1034,50 @@ void main() {
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
}