Fix TableRow with no children throws unnamed assertion (#123770)
Fix `TableRow` with no children throws unnamed assertion
This commit is contained in:
@@ -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;
|
||||
}()),
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user