【发布时间】:2022-01-22 19:11:15
【问题描述】:
我想实现只有 bool isActive 为 true 的 Tourneys 才能显示并按照 Toruney 日期最接近当前日期的顺序排序。
在List<NewPokerTourneyClass> avail 我得到三个锦标赛,这是正确的,但是当我想对List<NewPokerTourneyClass> avail 进行排序时,锦标赛没有得到排序。使用注释掉的排序功能,它可以对所有锦标赛进行排序,这不是我想要的。
ListView.builder(
scrollDirection: Axis.vertical,
itemCount: _pokerTourneyProvider.tourney!
.where((element) => element.isActive == true)
.length,
itemBuilder: (context, index) {
List<NewPokerTourneyClass> avail = _pokerTourneyProvider.tourney!
.where((element) => element.isActive == true)
.toList();
avail.sort((a, b) {
final one = a.dateTime?.millisecondsSinceEpoch;
final two = b.dateTime?.millisecondsSinceEpoch;
return one!.compareTo(two!);
});
// _pokerTourneyProvider.tourney!.sort((one, two) {
// final oneMilli = one.dateTime?.millisecondsSinceEpoch;
// final twoMilli = two.dateTime?.millisecondsSinceEpoch;
// return oneMilli!.compareTo(twoMilli!);
// });
【问题讨论】:
-
尝试将
List<NewPokerTourneyClass> avail = _pokerTourneyProvider.tourney! .where((element) => element.isActive == true) .toList(); avail.sort((a, b) { final one = a.dateTime?.millisecondsSinceEpoch; final two = b.dateTime?.millisecondsSinceEpoch; return one!.compareTo(two!); });移动到itembuilder之外,并检查它是否没有再次排序,例如处于初始化状态或其他状态