2024-05-09 09:46:23 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cpd/model/habit_list.dart';
|
|
|
|
|
|
|
|
class MyListView extends StatelessWidget {
|
2024-05-09 23:13:43 +02:00
|
|
|
const MyListView({Key? key});
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
),
|
|
|
|
),
|
|
|
|
onDismissed: (direction) {
|
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);
|
|
|
|
|
|
|
|
// 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-09 17:37:41 +02:00
|
|
|
title: Text(habits[index].title),
|
|
|
|
subtitle: Text(habits[index].subtitle ?? ''),
|
|
|
|
trailing: habits[index].icon,
|
2024-05-09 09:46:23 +02:00
|
|
|
leading: Checkbox(
|
2024-05-09 17:37:41 +02:00
|
|
|
value: habits[index].isComplete,
|
2024-05-09 09:46:23 +02:00
|
|
|
onChanged: (value) {
|
|
|
|
if (value == false) {
|
|
|
|
print("decrease counter");
|
|
|
|
} else {
|
|
|
|
print("increase counter");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|