Skip to content

Commit

Permalink
Merge branch 'maxim-saplin:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MogensO authored Mar 25, 2024
2 parents 7927cfb + 1919e3d commit af090e2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.5.12
- Add option to hide heading checkbox in data table PR#270

## 2.5.11
- Fixed Async example (range selector)
- Added `isHorizontalScrollBarVisible` and `isVerticalScrollBarVisible` to `PaginatedDataTable` and `AsyncPaginatedDataTable`
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
29 changes: 19 additions & 10 deletions lib/src/data_table_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class DataTable2 extends DataTable {
this.checkboxAlignment = Alignment.center,
this.bottomMargin,
super.columnSpacing,
this.showHeadingCheckBox = true,
super.showCheckboxColumn = true,
super.showBottomBorder = false,
super.dividerThickness,
Expand Down Expand Up @@ -249,6 +250,11 @@ class DataTable2 extends DataTable {
/// Defaults to the [Alignment.center]
final Alignment checkboxAlignment;

/// Whether to display heading checkbox or not if the checkbox column is present. Defaults to true.
/// Also check [DataTable.showCheckboxColumn] for details
/// on how to control the checkbox column visibility
final bool showHeadingCheckBox;

/// Overrides theme of the checkbox that is displayed in the checkbox column
/// in each data row (should checkboxes be enabled)
final CheckboxThemeData? datarowCheckboxTheme;
Expand Down Expand Up @@ -1163,16 +1169,19 @@ class DataTable2 extends DataTable {
tableColumns[0] = FixedColumnWidth(checkBoxWidth);

// Create heading twice, in the heading row used as back-up for the case of no data and any of the xxx_rows table
headingRow.children[0] = _buildCheckbox(
context: context,
checked: someChecked ? null : allChecked,
onRowTap: null,
onCheckboxChanged: (bool? checked) =>
_handleSelectAll(checked, someChecked),
overlayColor: null,
checkboxTheme: headingCheckboxTheme,
tristate: true,
rowHeight: headingHeight);

headingRow.children[0] = showHeadingCheckBox
? _buildCheckbox(
context: context,
checked: someChecked ? null : allChecked,
onRowTap: null,
onCheckboxChanged: (bool? checked) =>
_handleSelectAll(checked, someChecked),
overlayColor: null,
checkboxTheme: headingCheckboxTheme,
tristate: true,
rowHeight: headingHeight)
: SizedBox(height: headingHeight,);

if (fixedCornerRows != null) {
fixedCornerRows[0].children[0] = headingRow.children[0];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: data_table_2
description: In-place substitute for Flutter's DataTable and PaginatedDataTable with fixed/sticky headers and few extra features
version: 2.5.11
version: 2.5.12
homepage: https://github.com/maxim-saplin/data_table_2
repository: https://github.com/maxim-saplin/data_table_2

Expand Down
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 af090e2

Please sign in to comment.