mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
任务列表排序
This commit is contained in:
@@ -6,6 +6,13 @@ import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
import 'package:qinglong_app/utils/extension.dart';
|
||||
|
||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||
Map<int, int> sort = {
|
||||
0: 0,
|
||||
5: 1,
|
||||
3: 2,
|
||||
1: 3,
|
||||
4: 4,
|
||||
};
|
||||
|
||||
class TaskViewModel extends BaseViewModel {
|
||||
List<TaskBean> list = [];
|
||||
@@ -33,12 +40,12 @@ class TaskViewModel extends BaseViewModel {
|
||||
}
|
||||
|
||||
void sortList() {
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].isPinned == 1) {
|
||||
final TaskBean item = list.removeAt(i);
|
||||
list.insert(0, item);
|
||||
}
|
||||
}
|
||||
list.sort((TaskBean a, TaskBean b) {
|
||||
int? sortA = (a.isPinned == 1 && a.status != 0) ? 5 : ((a.isDisabled == 1 && a.status != 0) ? 4 : a.status);
|
||||
int? sortB = (b.isPinned == 1 && b.status != 0) ? 5 : ((b.isDisabled == 1 && b.status != 0) ? 4 : b.status);
|
||||
|
||||
return sort[sortA!]! - sort[sortB!]!;
|
||||
});
|
||||
|
||||
running.clear();
|
||||
running.addAll(list.where((element) => element.status == 0));
|
||||
|
||||
Reference in New Issue
Block a user