46 lines
1.1 KiB
Dart
46 lines
1.1 KiB
Dart
|
import 'package:flutter/foundation.dart';
|
||
|
import '../models/todo.dart';
|
||
|
|
||
|
class ToDoProvider with ChangeNotifier {
|
||
|
List<ToDo> _todos = [];
|
||
|
|
||
|
List<ToDo> get todos => _todos;
|
||
|
|
||
|
void addTask(ToDo todo) {
|
||
|
_todos.add(todo);
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
void removeTask(int index) {
|
||
|
_todos.removeAt(index);
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
void toggleCompletion(int index) {
|
||
|
_todos[index].isCompleted = !_todos[index].isCompleted;
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
// Sortierlogik für Deadline
|
||
|
void sortByDeadline() {
|
||
|
_todos.sort((a, b) {
|
||
|
if (a.deadline == null) return 1; // Tasks without deadline should come last
|
||
|
if (b.deadline == null) return -1;
|
||
|
return a.deadline!.compareTo(b.deadline!);
|
||
|
});
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
// Sortierlogik für Priorität
|
||
|
void sortByPriority() {
|
||
|
Map<String, int> priorityMap = {'High': 1, 'Medium': 2, 'Low': 3};
|
||
|
_todos.sort((a, b) => priorityMap[a.priority]!.compareTo(priorityMap[b.priority]!));
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
// Sortierlogik für Status
|
||
|
void sortByStatus() {
|
||
|
_todos.sort((a, b) => a.isCompleted ? 1 : -1); // Uncompleted first
|
||
|
notifyListeners();
|
||
|
}
|
||
|
}
|