import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cpd/model/habit_list.dart'; class MyListView extends StatelessWidget { const MyListView({Key? key}); @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( key: Key(habits[index].title), background: Container( color: Colors.blue, alignment: Alignment.centerLeft, child: const Padding( padding: EdgeInsets.only(left: 16), child: Icon(Icons.edit), ), ), secondaryBackground: Container( color: Colors.red, alignment: Alignment.centerRight, child: const Padding( padding: EdgeInsets.only(right: 16), child: Icon(Icons.delete), ), ), onDismissed: (direction) { // 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 } }, child: ListTile( title: Text(habits[index].title), subtitle: Text(habits[index].subtitle ?? ''), trailing: habits[index].icon, leading: Checkbox( value: habits[index].isComplete, onChanged: (value) { if (value == false) { print("decrease counter"); } else { print("increase counter"); } }, ), ), ), ), ); }, ); } }