Unverified Commit 430c57eb authored by Chinmoy's avatar Chinmoy Committed by GitHub

Modified DataRow to be disabled when onSelectChanged is not set (#80184)

This change prevents DataRow from being enabled when onSelectChanged is null.
parent 728a1933
......@@ -1018,7 +1018,7 @@ class DataTable extends StatelessWidget {
tableRows[rowIndex].children![0] = _buildCheckbox(
context: context,
checked: row.selected,
onRowTap: () => row.onSelectChanged?.call(!row.selected),
onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
onCheckboxChanged: row.onSelectChanged,
overlayColor: row.color ?? effectiveDataRowColor,
tristate: false,
......@@ -1084,7 +1084,7 @@ class DataTable extends StatelessWidget {
onLongPress: cell.onLongPress,
onTapCancel: cell.onTapCancel,
onTapDown: cell.onTapDown,
onSelectChanged: () => row.onSelectChanged?.call(!row.selected),
onSelectChanged: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
overlayColor: row.color ?? effectiveDataRowColor,
);
rowIndex += 1;
......
......@@ -1629,4 +1629,39 @@ void main() {
_customHorizontalMargin,
);
});
testWidgets('DataRow is disabled when onSelectChanged is not set', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DataTable(
columns: const <DataColumn>[
DataColumn(label: Text('Col1')),
DataColumn(label: Text('Col2')),
],
rows: <DataRow>[
DataRow(cells: const <DataCell>[
DataCell(Text('Hello')),
DataCell(Text('world')),
],
onSelectChanged: (bool? value) {},
),
const DataRow(cells: <DataCell>[
DataCell(Text('Bug')),
DataCell(Text('report')),
]),
const DataRow(cells: <DataCell>[
DataCell(Text('GitHub')),
DataCell(Text('issue')),
]),
],
),
),
),
);
expect(find.widgetWithText(TableRowInkWell, 'Hello'), findsOneWidget);
expect(find.widgetWithText(TableRowInkWell, 'Bug'), findsNothing);
expect(find.widgetWithText(TableRowInkWell, 'GitHub'), findsNothing);
});
}
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