Commit cb2ac0a1 authored by KyleWong's avatar KyleWong Committed by xster

Null check logic for datatable. (#27632)

parent 73855918
......@@ -543,7 +543,7 @@ class DataTable extends StatelessWidget {
tableRows[rowIndex].children[0] = _buildCheckbox(
color: theme.accentColor,
checked: row.selected,
onRowTap: () => row.onSelectChanged(!row.selected),
onRowTap: () => row.onSelectChanged != null ? row.onSelectChanged(!row.selected) : null ,
onCheckboxChanged: row.onSelectChanged,
);
rowIndex += 1;
......@@ -568,7 +568,7 @@ class DataTable extends StatelessWidget {
label: column.label,
tooltip: column.tooltip,
numeric: column.numeric,
onSort: () => column.onSort(dataColumnIndex, sortColumnIndex == dataColumnIndex ? !sortAscending : true),
onSort: () => column.onSort != null ? column.onSort(dataColumnIndex, sortColumnIndex == dataColumnIndex ? !sortAscending : true) : null,
sorted: dataColumnIndex == sortColumnIndex,
ascending: sortAscending,
);
......@@ -583,7 +583,7 @@ class DataTable extends StatelessWidget {
placeholder: cell.placeholder,
showEditIcon: cell.showEditIcon,
onTap: cell.onTap,
onSelectChanged: () => row.onSelectChanged(!row.selected),
onSelectChanged: () => row.onSelectChanged != null ? row.onSelectChanged(!row.selected) : null,
);
rowIndex += 1;
}
......
......@@ -210,4 +210,61 @@ void main() {
expect(tester.renderObject<RenderBox>(find.byType(Row).first).size.width, lessThan(800.0));
expect(tester.takeException(), isNull);
});
testWidgets('DataTable column onSort test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text('Dessert'),
),
],
rows: const <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(
Text('Lollipop'), // wraps
),
],
),
],
),
),
),
);
await tester.tap(find.text('Dessert'));
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('DataTable row onSelectChanged test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text('Dessert'),
),
],
rows: const <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(
Text('Lollipop'), // wraps
),
],
),
],
),
),
),
);
await tester.tap(find.text('Lollipop'));
await tester.pump();
expect(tester.takeException(), isNull);
});
}
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