您好,我想知道如何更改指示Datatable上所选元素数量的文本。
我希望选择“1次配送”,而不是“选择1次配送”。
class DeliveryTableSource extends DataTableSource {
List<RequestDeliverySource> _list;
int _rowSelectedCount = 0;
DeliveryTableSource(this._list);
@override
DataRow getRow(int index) {
if (index < 0 || index > _list.length)
return null;
else {
RequestDeliverySource source = _list[index];
return DataRow.byIndex(
cells: buildCells(source),
index: index,
selected: source.isSelected,
onSelectChanged: (bool value) {
if (source.isSelected != value) {
_rowSelectedCount += value ? 1 : -1;
source.isSelected = value;
notifyListeners();
}
});
}
}
List<DataCell> buildCells(RequestDeliverySource source) {
return [
DataCell(Text("${source.name}")),
DataCell(Text("${source.deliveryAddress}")),
DataCell(Text("${source.pickupAddress}")),
DataCell(Text("${source.plannedDeliveryDate}")),
DataCell(Text("${source.effectiveDeliveryDate}")),
DataCell(Text("${source.showStatus()}"))
];
}
void selectedAll(bool checked) {
_list.forEach((source) {
source.isSelected = checked;
});
_rowSelectedCount = checked ? _list.length : 0;
notifyListeners();
}
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => _list.length;
@override
int get selectedRowCount => _rowSelectedCount;
}
我的组件小部件表:
class DeliveryTable extends StatefulWidget {
DeliveryTable({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return new DeliveryTableState();
}
}
class DeliveryTableState extends State<DeliveryTable> {
int _rowsPerPage = 10;
@override
Widget build(BuildContext context) {
RequestDelivery delivery = new RequestDelivery();
delivery.name = "livraison test";
RequestDeliverySource source = new RequestDeliverySource(delivery);
DeliveryTableSource tableSource = new DeliveryTableSource([source]);
return Container(
width: double.infinity,
child: SingleChildScrollView(
child: PaginatedDataTable(
header: Text("Livraison effectuée",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16.0)),
rowsPerPage: _rowsPerPage,
onSelectAll: tableSource.selectedAll,
onRowsPerPageChanged: (int value) {
setState(() {
_rowsPerPage = value;
});
},
columns: _buildColumns(),
source: tableSource)));
}
List<DataColumn> _buildColumns() {
return [
DataColumn(label: Text("Nom"), tooltip: "Nom de la livraison"),
DataColumn(
label: Text("Lieux de livraison"), tooltip: "Adresse de livraison"),
DataColumn(
label: Text("Lieux de ramassage"), tooltip: "Adresse de ramassage"),
DataColumn(
label: Text("Date de livraison"), tooltip: "Date de livraison"),
DataColumn(
label: Text("Livrée le"), tooltip: "Date de livraison effective"),
DataColumn(label: Text("Statut"), tooltip: "Statu de la livraison")
];
}
}