Unverified Commit 8a7fd39b authored by Per Classon's avatar Per Classon Committed by GitHub

[Material] Parent checkbox in DataTable should deselect all, if children...

[Material] Parent checkbox in DataTable should deselect all, if children checkboxes are disabled or selected  (#67938)
parent 06722679
......@@ -868,9 +868,10 @@ class DataTable extends StatelessWidget {
);
final bool anyRowSelectable = rows.any((DataRow row) => row.onSelectChanged != null);
final bool displayCheckboxColumn = showCheckboxColumn && anyRowSelectable;
final Iterable<DataRow> rowsChecked = displayCheckboxColumn ?
rows.where((DataRow row) => row.onSelectChanged != null && row.selected) : <DataRow>[];
final bool allChecked = displayCheckboxColumn && rowsChecked.length == rows.length;
final Iterable<DataRow> rowsWithCheckbox = displayCheckboxColumn ?
rows.where((DataRow row) => row.onSelectChanged != null) : <DataRow>[];
final Iterable<DataRow> rowsChecked = rowsWithCheckbox.where((DataRow row) => row.selected);
final bool allChecked = displayCheckboxColumn && rowsChecked.length == rowsWithCheckbox.length;
final bool anyChecked = displayCheckboxColumn && rowsChecked.isNotEmpty;
final bool someChecked = anyChecked && !allChecked;
final double effectiveHorizontalMargin = horizontalMargin
......
......@@ -107,7 +107,7 @@ void main() {
testWidgets('DataTable control test - tristate', (WidgetTester tester) async {
final List<String> log = <String>[];
const int numItems = 3;
Widget buildTable(List<bool> selected) {
Widget buildTable(List<bool> selected, {int? disabledIndex}) {
return DataTable(
onSelectAll: (bool? value) {
log.add('select-all: $value');
......@@ -123,7 +123,7 @@ void main() {
(int index) => DataRow(
cells: <DataCell>[DataCell(Text('Row $index'))],
selected: selected[index],
onSelectChanged: (bool? value) {
onSelectChanged: index == disabledIndex ? null : (bool? value) {
log.add('row-selected: $index');
},
),
......@@ -157,6 +157,21 @@ void main() {
expect(log, <String>['select-all: false']);
log.clear();
// Tapping the parent checkbox when all rows are selected and one is
// disabled, deselects all.
await tester.pumpWidget(MaterialApp(
home: Material(
child: buildTable(
<bool>[true, true, false],
disabledIndex: 2,
),
),
));
await tester.tap(find.byType(Checkbox).first);
expect(log, <String>['select-all: false']);
log.clear();
});
testWidgets('DataTable control test - no checkboxes', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment