import 'package:flutter/material.dart'; import 'package:todo/database/andereAbspeicherung.dart'; import '../database/Sqlite.dart'; import 'ToDoItem.dart'; class ToDoProvider with ChangeNotifier { List _toDoList = []; final safeHelper = andereAbspeicherung(); List get toDoList => _toDoList; ToDoProvider() { _loadFromPrefs(); } Future 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 _loadFromPrefs() async { List 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(); } }