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.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.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
|
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:flutter/material.dart';
|
||||||
import 'package:todo/database/andereAbspeicherung.dart';
|
import 'package:todo/database/PathProvider.dart';
|
||||||
import '../database/Sqlite.dart';
|
import '../database/Sqlite.dart';
|
||||||
import 'ToDoItem.dart';
|
import 'ToDoItem.dart';
|
||||||
|
|
||||||
class ToDoProvider with ChangeNotifier {
|
class ToDoProvider with ChangeNotifier {
|
||||||
List<ToDoItem> _toDoList = [];
|
final List<ToDoItem> _toDoList = [];
|
||||||
final safeHelper = andereAbspeicherung();
|
final safeHelper = Sqlite();
|
||||||
List<ToDoItem> get toDoList => _toDoList;
|
List<ToDoItem> get toDoList => _toDoList;
|
||||||
|
|
||||||
ToDoProvider() {
|
ToDoProvider() {
|
||||||
|
@ -25,11 +25,17 @@ class ToDoProvider with ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteItem(int id) {
|
||||||
|
_toDoList.remove(_toDoList.where((toDoID) => toDoID.id == id).first);
|
||||||
|
safeHelper.deleteToDoItem(id);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _loadFromPrefs() async {
|
Future<void> _loadFromPrefs() async {
|
||||||
List<ToDoItem> items = await safeHelper.getToDoItems();
|
List<ToDoItem> items = await safeHelper.getToDoItems();
|
||||||
items.forEach((item) {
|
for (var item in items) {
|
||||||
_toDoList.add(item);
|
_toDoList.add(item);
|
||||||
});
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ abstract class DatabaseInterface {
|
||||||
Future<void> insertToDoItem(ToDoItem item);
|
Future<void> insertToDoItem(ToDoItem item);
|
||||||
Future<List<ToDoItem>> getToDoItems();
|
Future<List<ToDoItem>> getToDoItems();
|
||||||
Future<void> updateToDoItem(ToDoItem item);
|
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/buisness/ToDoItem.dart';
|
||||||
import 'package:todo/database/DatabaseInterface.dart';
|
import 'package:todo/database/DatabaseInterface.dart';
|
||||||
|
|
||||||
class andereAbspeicherung implements DatabaseInterface {
|
class PathProvider implements DatabaseInterface {
|
||||||
Future<String> get _localPath async {
|
Future<String> get _localPath async {
|
||||||
final directory = await getApplicationDocumentsDirectory();
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
return directory.path;
|
return directory.path;
|
||||||
|
@ -26,8 +26,8 @@ class andereAbspeicherung implements DatabaseInterface {
|
||||||
final contents = await file.readAsString();
|
final contents = await file.readAsString();
|
||||||
List<dynamic> contentJson = jsonDecode(contents);
|
List<dynamic> contentJson = jsonDecode(contents);
|
||||||
|
|
||||||
List<ToDoItem> _toDoList = contentJson.map((item) => ToDoItem.fromMap(item)).toList();
|
List<ToDoItem> toDoList = contentJson.map((item) => ToDoItem.fromMap(item)).toList();
|
||||||
return _toDoList;
|
return toDoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -45,4 +45,12 @@ class andereAbspeicherung implements DatabaseInterface {
|
||||||
return file.writeAsString(item.toMap() as String);
|
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
|
// ToDoItem hinzufügen
|
||||||
|
@override
|
||||||
Future<void> insertToDoItem(ToDoItem item) async {
|
Future<void> insertToDoItem(ToDoItem item) async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
final id = await db.insert(
|
final id = await db.insert(
|
||||||
|
@ -50,6 +51,7 @@ class Sqlite implements DatabaseInterface {
|
||||||
item.id = id;
|
item.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
Future<List<ToDoItem>> getToDoItems() async {
|
Future<List<ToDoItem>> getToDoItems() async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
final List<Map<String, dynamic>> maps = await db.query('todo_items');
|
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 {
|
Future<void> deleteToDoItem(int id) async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
await db.delete(
|
await db.delete(
|
||||||
|
@ -68,6 +71,7 @@ class Sqlite implements DatabaseInterface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
Future<void> updateToDoItem(ToDoItem item) async {
|
Future<void> updateToDoItem(ToDoItem item) async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
await db.update(
|
await db.update(
|
||||||
|
|
|
@ -8,17 +8,17 @@ class ToDoExpandableWidget extends StatelessWidget {
|
||||||
final int id;
|
final int id;
|
||||||
|
|
||||||
const ToDoExpandableWidget({
|
const ToDoExpandableWidget({
|
||||||
Key? key,
|
super.key,
|
||||||
required this.toDoItem,
|
required this.toDoItem,
|
||||||
required this.id,
|
required this.id,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
color: Colors.orange[100],
|
color: Colors.orange[100],
|
||||||
child: ExpansionTile(
|
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()}'),
|
subtitle: Text('Due: ${toDoItem.dueDate.toLocal()}'),
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
|
@ -26,12 +26,23 @@ class ToDoExpandableWidget extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text('Description: ${toDoItem.description}', style: TextStyle(color: Colors.black)),
|
Text('Description: ${toDoItem.description}', style: const TextStyle(color: Colors.black)),
|
||||||
SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
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>(
|
DropdownButton<String>(
|
||||||
value: toDoItem.status,
|
value: toDoItem.status,
|
||||||
items: ['Pending', 'In Progress', 'Completed']
|
items: ['Pending', 'In Progress', 'Completed']
|
||||||
|
|
Loading…
Reference in New Issue