Skip to content

Commit

Permalink
Add test for the option to show or hide heading checkbox in data tables
Browse files Browse the repository at this point in the history
  • Loading branch information
r-jbournon committed Mar 22, 2024
1 parent b081743 commit cb100c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/custom_features_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1981,8 +1981,47 @@ void main() {
expect(d.length, kDesserts.length);
expect((d.first.widget as Theme).child.runtimeType, Checkbox);
});

testWidgets('DataTable2 heading checkbox', (WidgetTester tester) async {
final List<DataColumn2> columns = [
const DataColumn2(label: Text('Column1')),
];
final List<DataRow2> rows = [
DataRow2(
onSelectChanged: (value) {},
cells: const [DataCell(Text('Content1'))],
),
];

// Check if heading checkbox is shown by default
await wrapWidgetSetSurf(
tester,
buildTable(
columns: columns,
rows: rows,
));

await tester.pumpAndSettle();
expect(find.text('Column1'), findsOneWidget);
expect(find.byType(Checkbox), findsNWidgets(2));

// Check if heading checkbox is hided
await wrapWidgetSetSurf(
tester,
buildTable(
showHeadingCheckbox: false,
columns: columns,
rows: rows,
));

await tester.pumpAndSettle();
expect(find.text('Column1'), findsOneWidget);
expect(find.byType(Checkbox), findsOneWidget);
});
}



Tripple<Size> _getColumnSizes(WidgetTester tester, bool header) {
var s0 = tester.getSize(find.byType(DataTable2));

Expand Down
2 changes: 2 additions & 0 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ DataTable2 buildTable(
Color? fixedCornerColor,
Color? headingRowColor,
BoxDecoration? headingRowDecoration,
bool showHeadingCheckbox = true,
double? dividerThickness,
bool showBottomBorder = false,
TableBorder? border,
Expand All @@ -172,6 +173,7 @@ DataTable2 buildTable(
sortArrowIcon: sortArrowIcon ?? Icons.arrow_upward,
headingRowColor: MaterialStatePropertyAll(headingRowColor),
headingRowDecoration: headingRowDecoration,
showHeadingCheckBox: showHeadingCheckbox,
sortArrowAnimationDuration:
sortArrowAnimationDuration ?? const Duration(milliseconds: 150),
minWidth: minWidth,
Expand Down

0 comments on commit cb100c4

Please sign in to comment.