mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Null check logic for datatable. (#27632)
This commit is contained in:
parent
738559188c
commit
cb2ac0a125
@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user