我想根据开始日期和结束日期获取数据表的行。
假设我的开始日期是“2021-09-08”,结束日期是“2021-10-08”。
基于这些日期,我想要使用颤振的分页数据表的行。我想要使用以下列表的开始日期和结束日期之间的日期。下面的代码适用于数据表,但我需要分页数据表。
class MyData extends DataTableSource {
final List<UserView> _data = [];
List<UserView> userData = [
UserView(
date: '4-6-2021',
description: 'Product Ordered',
amount: 189.14,
status: '0'), .........
];
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => userData.length;
@override
int get selectedRowCount => 0;
@override
DataRow getRow(int index) {
return DataRow(cells: [
DataCell(Text(userData[index].date)),
DataCell(Text(userData[index].description)),
DataCell(Text('${userData[index].amount}')),
]);
}
}
下面是有状态的小部件类
class UserViewPageState {
final DataTableSource _data = MyData();
List<UserView> _foundUsers = [];
late DateTime from = DateTime.now();
late DateTime to = DateTime.now();
......
PaginatedDataTable(
source: _data,
columns: const [
DataColumn(label: Text('Date')),
DataColumn(label: Text('Description')),
DataColumn(label: Text('Amount')),
DataColumn(label: Text('Status')),
],
columnSpacing: 20,
horizontalMargin: 10,
rowsPerPage: 6,
showCheckboxColumn: false,
),
搜索条形码但不起作用
void _runFilter(String enteredKeyword) {
List<UserView> results = [];
if (enteredKeyword.isEmpty) {
results = d;
} else {
results = d
.where((name) =>
name.date.toLowerCase().contains(enteredKeyword.toLowerCase()) ||
name.description
.toString()
.contains(enteredKeyword.toLowerCase()))
.cast<UserView>()
.toList();
}
setState(() {
_foundUsers = results;
});
}
日期过滤代码但不起作用
late DateTime from = DateTime.now();
late DateTime to = DateTime.now();
Future<void> _selectDate(BuildContext context, int i) async {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2015),
lastDate: DateTime(2050));
if (pickedDate != null) {
if (i == 0) {
setState(() {
from = pickedDate;
});
} else if (i == 1) {
setState(() {
to = pickedDate;
getdaysInBetween();
});
}
}
}
getdaysInBetween() {
List<UserView> results = [];
results = _usersViewData.where((user) {
final currentDate = DateTime.tryParse(user.date);
return currentDate != null &&
currentDate.isAfter(from.subtract(const Duration(days: 1))) &&
currentDate.isBefore(to.add(const Duration(days: 1)));
}).toList();
setState(() {
_foundRows = results;
});
}
如何使用搜索栏、Fromdate 和 Todate 的功能。