52 lines
1.2 KiB
Dart
52 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:todo/database/andereAbspeicherung.dart';
|
|
import '../database/Sqlite.dart';
|
|
import 'ToDoItem.dart';
|
|
|
|
class ToDoProvider with ChangeNotifier {
|
|
List<ToDoItem> _toDoList = [];
|
|
final safeHelper = andereAbspeicherung();
|
|
List<ToDoItem> get toDoList => _toDoList;
|
|
|
|
ToDoProvider() {
|
|
_loadFromPrefs();
|
|
}
|
|
|
|
Future<void> addToDo(ToDoItem item) async {
|
|
await safeHelper.insertToDoItem(item);
|
|
_toDoList.add(item);
|
|
notifyListeners();
|
|
}
|
|
|
|
void updateStatus(int id, String status) {
|
|
ToDoItem item = _toDoList.firstWhere((todo) => todo.id == id);
|
|
item.status = status;
|
|
safeHelper.updateToDoItem(item);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> _loadFromPrefs() async {
|
|
List<ToDoItem> items = await safeHelper.getToDoItems();
|
|
items.forEach((item) {
|
|
_toDoList.add(item);
|
|
});
|
|
notifyListeners();
|
|
}
|
|
|
|
void sortByName() {
|
|
_toDoList.sort((a, b) => a.name.compareTo(b.name));
|
|
notifyListeners();
|
|
}
|
|
|
|
void sortByDueDate() {
|
|
_toDoList.sort((a, b) => a.dueDate.compareTo(b.dueDate));
|
|
notifyListeners();
|
|
}
|
|
|
|
void sortByStatus() {
|
|
_toDoList.sort((a, b) => a.status.compareTo(b.status));
|
|
notifyListeners();
|
|
}
|
|
|
|
}
|