Skip to content

Commit

Permalink
Add option to hide heading checkbox in data table
Browse files Browse the repository at this point in the history
A boolean option `showHeadingCheckBox` has been added to the data table configuration. This allows the user to choose whether to display the heading checkbox or not. In cases where the checkbox is not needed, a sized box takes its place instead.
  • Loading branch information
r-jbournon committed Mar 22, 2024
1 parent 2e204cf commit b081743
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 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,10 @@ class DataTable2 extends DataTable {
/// Defaults to the [Alignment.center]
final Alignment checkboxAlignment;

/// Display heading checkbox
/// Default set to true
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 +1168,17 @@ 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) : const SizedBox();

if (fixedCornerRows != null) {
fixedCornerRows[0].children[0] = headingRow.children[0];
Expand Down

0 comments on commit b081743

Please sign in to comment.