Clean up + forgotten delete button
parent
9087a6e2ad
commit
f83dedda4a
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
4ce773e731e1e39724cb610f05740b61838e916f
|
||||
b1dbbd5f3120f7b6042aa8334edab1c8b68a8aa6
|
Binary file not shown.
|
@ -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<ToDoItem> _toDoList = [];
|
||||
final safeHelper = andereAbspeicherung();
|
||||
final List<ToDoItem> _toDoList = [];
|
||||
final safeHelper = Sqlite();
|
||||
List<ToDoItem> 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<void> _loadFromPrefs() async {
|
||||
List<ToDoItem> items = await safeHelper.getToDoItems();
|
||||
items.forEach((item) {
|
||||
for (var item in items) {
|
||||
_toDoList.add(item);
|
||||
});
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,4 +7,5 @@ abstract class DatabaseInterface {
|
|||
Future<void> insertToDoItem(ToDoItem item);
|
||||
Future<List<ToDoItem>> getToDoItems();
|
||||
Future<void> updateToDoItem(ToDoItem item);
|
||||
Future<void> deleteToDoItem(int id);
|
||||
}
|
|
@ -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<String> get _localPath async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
return directory.path;
|
||||
|
@ -26,8 +26,8 @@ class andereAbspeicherung implements DatabaseInterface {
|
|||
final contents = await file.readAsString();
|
||||
List<dynamic> contentJson = jsonDecode(contents);
|
||||
|
||||
List<ToDoItem> _toDoList = contentJson.map((item) => ToDoItem.fromMap(item)).toList();
|
||||
return _toDoList;
|
||||
List<ToDoItem> 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<File> deleteToDoItem(int id) async {
|
||||
final file = await _localFile;
|
||||
List<ToDoItem> l = await getToDoItems();
|
||||
l.remove(l.where((item) => item.id == id).first);
|
||||
return file.writeAsString(jsonEncode(l.map((item) => item.toMap()).toList()));
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,7 @@ class Sqlite implements DatabaseInterface {
|
|||
}
|
||||
|
||||
// ToDoItem hinzufügen
|
||||
@override
|
||||
Future<void> 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<List<ToDoItem>> getToDoItems() async {
|
||||
final db = await database;
|
||||
final List<Map<String, dynamic>> maps = await db.query('todo_items');
|
||||
|
@ -59,6 +61,7 @@ class Sqlite implements DatabaseInterface {
|
|||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteToDoItem(int id) async {
|
||||
final db = await database;
|
||||
await db.delete(
|
||||
|
@ -68,6 +71,7 @@ class Sqlite implements DatabaseInterface {
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateToDoItem(ToDoItem item) async {
|
||||
final db = await database;
|
||||
await db.update(
|
||||
|
|
|
@ -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<ToDoProvider>(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<String>(
|
||||
value: toDoItem.status,
|
||||
items: ['Pending', 'In Progress', 'Completed']
|
||||
|
|
Loading…
Reference in New Issue