feat:增加待办排序UI功能

This commit is contained in:
2025-11-20 11:47:35 +08:00
parent 565b04e65d
commit b2260d139b
4 changed files with 101 additions and 10 deletions

View File

@@ -15,9 +15,29 @@ class TodoService {
}
}
List<Todo> getAllTodos() {
return box.values.toList()
..sort((a, b) => b.updateTime.compareTo(a.updateTime));
List<Todo> getAllTodos(TodoSortMode mode) {
if (mode == TodoSortMode.time) {
return box.values.toList()
..sort((a, b) {
// 先按是否有 dueDate 分组:有时间的排前面
if (a.dueDate != null && b.dueDate == null) {
return -1; // a有时间b没有时间a排在前面
} else if (a.dueDate == null && b.dueDate != null) {
return 1; // a没有时间b有时间b排在前面
}
// 都有 dueDate按 dueDate 排序
else if (a.dueDate != null && b.dueDate != null) {
return a.dueDate!.compareTo(b.dueDate!); // 最近的在前面
}
// 都没有 dueDate按 updateTime 排序
else {
return b.updateTime.compareTo(a.updateTime); // 最近的在前面
}
});
} else {
return box.values.toList()
..sort((a, b) => b.priorityIndex.compareTo(a.priorityIndex));
}
}
List<Todo> getAllTodosByYear(int year) {