diff --git a/build/app/intermediates/assets/debug/flutter_assets/kernel_blob.bin b/build/app/intermediates/assets/debug/flutter_assets/kernel_blob.bin index d71fe28..3966e74 100644 Binary files a/build/app/intermediates/assets/debug/flutter_assets/kernel_blob.bin and b/build/app/intermediates/assets/debug/flutter_assets/kernel_blob.bin differ diff --git a/build/app/intermediates/compressed_assets/debug/out/assets/flutter_assets/kernel_blob.bin.jar b/build/app/intermediates/compressed_assets/debug/out/assets/flutter_assets/kernel_blob.bin.jar index 4a467d9..2d0dedc 100644 Binary files a/build/app/intermediates/compressed_assets/debug/out/assets/flutter_assets/kernel_blob.bin.jar and b/build/app/intermediates/compressed_assets/debug/out/assets/flutter_assets/kernel_blob.bin.jar differ diff --git a/build/app/intermediates/flutter/debug/flutter_assets/kernel_blob.bin b/build/app/intermediates/flutter/debug/flutter_assets/kernel_blob.bin index d71fe28..3966e74 100644 Binary files a/build/app/intermediates/flutter/debug/flutter_assets/kernel_blob.bin and b/build/app/intermediates/flutter/debug/flutter_assets/kernel_blob.bin differ diff --git a/build/app/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt b/build/app/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt index d318b6d..6abe8be 100644 --- a/build/app/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt +++ b/build/app/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt @@ -1,4 +1,4 @@ -#Tue Oct 29 11:57:46 CET 2024 +#Tue Oct 29 18:01:57 CET 2024 base.0=/Users/user/Documents/Programmierung/CPD/cpd_2024_todo/build/app/intermediates/dex/debug/mergeExtDexDebug/classes.dex base.1=/Users/user/Documents/Programmierung/CPD/cpd_2024_todo/build/app/intermediates/dex/debug/mergeLibDexDebug/0/classes.dex base.2=/Users/user/Documents/Programmierung/CPD/cpd_2024_todo/build/app/intermediates/dex/debug/mergeProjectDexDebug/0/classes.dex diff --git a/build/app/outputs/apk/debug/app-debug.apk b/build/app/outputs/apk/debug/app-debug.apk index a116a4c..8bc2c7d 100644 Binary files a/build/app/outputs/apk/debug/app-debug.apk and b/build/app/outputs/apk/debug/app-debug.apk differ diff --git a/build/app/outputs/flutter-apk/app-debug.apk b/build/app/outputs/flutter-apk/app-debug.apk index a116a4c..8bc2c7d 100644 Binary files a/build/app/outputs/flutter-apk/app-debug.apk and b/build/app/outputs/flutter-apk/app-debug.apk differ diff --git a/build/app/outputs/flutter-apk/app-debug.apk.sha1 b/build/app/outputs/flutter-apk/app-debug.apk.sha1 index 53083db..93fdc9d 100644 --- a/build/app/outputs/flutter-apk/app-debug.apk.sha1 +++ b/build/app/outputs/flutter-apk/app-debug.apk.sha1 @@ -1 +1 @@ -4ce773e731e1e39724cb610f05740b61838e916f \ No newline at end of file +b1dbbd5f3120f7b6042aa8334edab1c8b68a8aa6 \ No newline at end of file diff --git a/build/f872507f30e2ff2523f0f1d19160266e.cache.dill.track.dill b/build/f872507f30e2ff2523f0f1d19160266e.cache.dill.track.dill index d71fe28..3966e74 100644 Binary files a/build/f872507f30e2ff2523f0f1d19160266e.cache.dill.track.dill and b/build/f872507f30e2ff2523f0f1d19160266e.cache.dill.track.dill differ diff --git a/lib/buisness/ToDoProvider.dart b/lib/buisness/ToDoProvider.dart index 0cff2ee..f952680 100644 --- a/lib/buisness/ToDoProvider.dart +++ b/lib/buisness/ToDoProvider.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:todo/database/andereAbspeicherung.dart'; +import 'package:todo/database/PathProvider.dart'; import '../database/Sqlite.dart'; import 'ToDoItem.dart'; class ToDoProvider with ChangeNotifier { - List _toDoList = []; - final safeHelper = andereAbspeicherung(); + final List _toDoList = []; + final safeHelper = Sqlite(); List get toDoList => _toDoList; ToDoProvider() { @@ -25,11 +25,17 @@ class ToDoProvider with ChangeNotifier { notifyListeners(); } + void deleteItem(int id) { + _toDoList.remove(_toDoList.where((toDoID) => toDoID.id == id).first); + safeHelper.deleteToDoItem(id); + notifyListeners(); + } + Future _loadFromPrefs() async { List items = await safeHelper.getToDoItems(); - items.forEach((item) { + for (var item in items) { _toDoList.add(item); - }); + } notifyListeners(); } diff --git a/lib/database/DatabaseInterface.dart b/lib/database/DatabaseInterface.dart index 67f3da2..8db3d05 100644 --- a/lib/database/DatabaseInterface.dart +++ b/lib/database/DatabaseInterface.dart @@ -7,4 +7,5 @@ abstract class DatabaseInterface { Future insertToDoItem(ToDoItem item); Future> getToDoItems(); Future updateToDoItem(ToDoItem item); + Future deleteToDoItem(int id); } \ No newline at end of file diff --git a/lib/database/andereAbspeicherung.dart b/lib/database/PathProvider.dart similarity index 73% rename from lib/database/andereAbspeicherung.dart rename to lib/database/PathProvider.dart index 39e908a..74feb49 100644 --- a/lib/database/andereAbspeicherung.dart +++ b/lib/database/PathProvider.dart @@ -5,7 +5,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:todo/buisness/ToDoItem.dart'; import 'package:todo/database/DatabaseInterface.dart'; -class andereAbspeicherung implements DatabaseInterface { +class PathProvider implements DatabaseInterface { Future get _localPath async { final directory = await getApplicationDocumentsDirectory(); return directory.path; @@ -26,8 +26,8 @@ class andereAbspeicherung implements DatabaseInterface { final contents = await file.readAsString(); List contentJson = jsonDecode(contents); - List _toDoList = contentJson.map((item) => ToDoItem.fromMap(item)).toList(); - return _toDoList; + List toDoList = contentJson.map((item) => ToDoItem.fromMap(item)).toList(); + return toDoList; } @override @@ -45,4 +45,12 @@ class andereAbspeicherung implements DatabaseInterface { return file.writeAsString(item.toMap() as String); } + @override + Future deleteToDoItem(int id) async { + final file = await _localFile; + List l = await getToDoItems(); + l.remove(l.where((item) => item.id == id).first); + return file.writeAsString(jsonEncode(l.map((item) => item.toMap()).toList())); + } + } \ No newline at end of file diff --git a/lib/database/Sqlite.dart b/lib/database/Sqlite.dart index 620c8d2..a073dd8 100644 --- a/lib/database/Sqlite.dart +++ b/lib/database/Sqlite.dart @@ -40,6 +40,7 @@ class Sqlite implements DatabaseInterface { } // ToDoItem hinzufügen + @override Future insertToDoItem(ToDoItem item) async { final db = await database; final id = await db.insert( @@ -50,6 +51,7 @@ class Sqlite implements DatabaseInterface { item.id = id; } + @override Future> getToDoItems() async { final db = await database; final List> maps = await db.query('todo_items'); @@ -59,6 +61,7 @@ class Sqlite implements DatabaseInterface { }); } + @override Future deleteToDoItem(int id) async { final db = await database; await db.delete( @@ -68,6 +71,7 @@ class Sqlite implements DatabaseInterface { ); } + @override Future updateToDoItem(ToDoItem item) async { final db = await database; await db.update( diff --git a/lib/presentation/ToDoExpandableWidget.dart b/lib/presentation/ToDoExpandableWidget.dart index cc2ddd3..a8ae2b0 100644 --- a/lib/presentation/ToDoExpandableWidget.dart +++ b/lib/presentation/ToDoExpandableWidget.dart @@ -8,17 +8,17 @@ class ToDoExpandableWidget extends StatelessWidget { final int id; const ToDoExpandableWidget({ - Key? key, + super.key, required this.toDoItem, required this.id, - }) : super(key: key); + }); @override Widget build(BuildContext context) { return Card( color: Colors.orange[100], child: ExpansionTile( - title: Text(toDoItem.name, style: TextStyle(color: Colors.black)), + title: Text(toDoItem.name, style: const TextStyle(color: Colors.black)), subtitle: Text('Due: ${toDoItem.dueDate.toLocal()}'), children: [ Padding( @@ -26,12 +26,23 @@ class ToDoExpandableWidget extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Description: ${toDoItem.description}', style: TextStyle(color: Colors.black)), - SizedBox(height: 10), + Text('Description: ${toDoItem.description}', style: const TextStyle(color: Colors.black)), + const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Status: ', style: TextStyle(color: Colors.black)), + ElevatedButton.icon( + onPressed: () { + Provider.of(context, listen: false).deleteItem(toDoItem.id!); + }, + icon: const Icon(Icons.delete), + label: const Text("Delete"), + style: ElevatedButton.styleFrom( + textStyle: const TextStyle(fontSize: 15), + iconColor: const Color(0xFFFF0000), + ), + ), + const Text('Status: ', style: TextStyle(color: Colors.black)), DropdownButton( value: toDoItem.status, items: ['Pending', 'In Progress', 'Completed']