Skip to content

Commit be23885

Browse files
authored
Fix TableRow with no children throws unnamed assertion (#123770)
Fix `TableRow` with no children throws unnamed assertion
1 parent 6a574ac commit be23885

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

packages/flutter/lib/src/widgets/table.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ class Table extends RenderObjectWidget {
144144
'Otherwise, the table will contain holes.',
145145
);
146146
}
147+
if (children.any((TableRow row) => row.children.isEmpty)) {
148+
throw FlutterError(
149+
'One or more TableRow have no children.\n'
150+
'Every TableRow in a Table must have at least one child, so there is no empty row. ',
151+
);
152+
}
147153
}
148154
return true;
149155
}()),

packages/flutter/test/widgets/table_test.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void main() {
4545
),
4646
);
4747
});
48+
4849
testWidgets('Table widget - control test', (WidgetTester tester) async {
4950
Future<void> run(TextDirection textDirection) async {
5051
await tester.pumpWidget(
@@ -1033,5 +1034,50 @@ void main() {
10331034
expect(find.text('Hello'), findsOneWidget);
10341035
});
10351036

1037+
testWidgets('TableRow with no children throws an error message', (WidgetTester tester) async {
1038+
// Regression test for https://github.com/flutter/flutter/issues/119541.
1039+
String result = 'no exception';
1040+
1041+
// Test TableRow with children.
1042+
try {
1043+
await tester.pumpWidget(Directionality(
1044+
textDirection: TextDirection.ltr,
1045+
child: Table(
1046+
children: const <TableRow>[
1047+
TableRow(
1048+
children: <Widget>[
1049+
Text('A'),
1050+
],
1051+
),
1052+
],
1053+
),
1054+
));
1055+
} on FlutterError catch (e) {
1056+
result = e.toString();
1057+
}
1058+
1059+
expect(result, 'no exception');
1060+
1061+
// Test TableRow with no children.
1062+
try {
1063+
await tester.pumpWidget(Directionality(
1064+
textDirection: TextDirection.ltr,
1065+
child: Table(
1066+
children: const <TableRow>[
1067+
TableRow(),
1068+
],
1069+
),
1070+
));
1071+
} on FlutterError catch (e) {
1072+
result = e.toString();
1073+
}
1074+
1075+
expect(
1076+
result,
1077+
'One or more TableRow have no children.\n'
1078+
'Every TableRow in a Table must have at least one child, so there is no empty row.',
1079+
);
1080+
});
1081+
10361082
// TODO(ianh): Test handling of TableCell object
10371083
}

0 commit comments

Comments
 (0)