2024-05-09 09:46:23 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-05-12 00:08:54 +02:00
|
|
|
import 'package:cpd/database/habit.dart';
|
|
|
|
import 'package:cpd/database/todo_db.dart';
|
|
|
|
import 'package:cpd/database/db.dart';
|
2024-05-09 09:46:23 +02:00
|
|
|
|
|
|
|
class MyListView extends StatelessWidget {
|
2024-05-12 00:08:54 +02:00
|
|
|
final List<Habit> habits;
|
|
|
|
final todoDB = TodoDB();
|
|
|
|
MyListView({super.key, required this.habits});
|
2024-05-09 23:13:43 +02:00
|
|
|
|
2024-05-09 09:46:23 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListView.builder(
|
|
|
|
shrinkWrap: true,
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
itemCount: habits.length,
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
2024-05-12 00:08:54 +02:00
|
|
|
final todo = habits[index];
|
|
|
|
|
2024-05-09 09:46:23 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
|
|
|
child: Card(
|
|
|
|
color: index % 2 == 0 ? Colors.green[300] : Colors.green[100],
|
|
|
|
child: Dismissible(
|
2024-05-09 17:37:41 +02:00
|
|
|
key: Key(habits[index].title),
|
2024-05-09 09:46:23 +02:00
|
|
|
background: Container(
|
2024-05-09 23:13:43 +02:00
|
|
|
color: Colors.blue,
|
2024-05-09 09:46:23 +02:00
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: const Padding(
|
|
|
|
padding: EdgeInsets.only(left: 16),
|
2024-05-09 23:13:43 +02:00
|
|
|
child: Icon(Icons.edit),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
secondaryBackground: Container(
|
|
|
|
color: Colors.red,
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: const Padding(
|
|
|
|
padding: EdgeInsets.only(right: 16),
|
|
|
|
child: Icon(Icons.delete),
|
2024-05-09 09:46:23 +02:00
|
|
|
),
|
|
|
|
),
|
2024-05-12 00:08:54 +02:00
|
|
|
onDismissed: (direction) async {
|
2024-05-09 23:13:43 +02:00
|
|
|
// Löschen
|
|
|
|
if (direction == DismissDirection.endToStart) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(content: Text("${habits[index].title} was dismissed"))
|
|
|
|
);
|
|
|
|
// Hier wird das Element aus der Liste entfernt
|
|
|
|
habits.removeAt(index);
|
2024-05-12 00:08:54 +02:00
|
|
|
//await todoDB.delete(todoDB.id);
|
2024-05-09 23:13:43 +02:00
|
|
|
|
|
|
|
// Ausgabe der aktualisierten Liste zur Kontrolle
|
|
|
|
print('Current list:');
|
|
|
|
habits.forEach((habit) {
|
|
|
|
print('${habit.title}: ${habit.subtitle}');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Bearbeiten
|
|
|
|
else if(direction == DismissDirection.startToEnd) {
|
|
|
|
//muss noch implementiert werden
|
|
|
|
}
|
2024-05-09 09:46:23 +02:00
|
|
|
},
|
|
|
|
child: ListTile(
|
2024-05-12 00:08:54 +02:00
|
|
|
title: Text(todo.title),
|
|
|
|
subtitle: Text(todo.subtitle ?? ''),
|
|
|
|
trailing: Text(todo.icon as String),
|
2024-05-09 09:46:23 +02:00
|
|
|
leading: Checkbox(
|
2024-05-12 00:08:54 +02:00
|
|
|
value: todo.isComplete,
|
2024-05-09 09:46:23 +02:00
|
|
|
onChanged: (value) {
|
|
|
|
if (value == false) {
|
|
|
|
print("decrease counter");
|
|
|
|
} else {
|
|
|
|
print("increase counter");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|