import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cpd/model/habit_list.dart'; class MyListView extends StatelessWidget { @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.red, alignment: Alignment.centerLeft, child: const Padding( padding: EdgeInsets.only(left: 16), child: Row( children: [ Icon(Icons.delete), ], ), ), ), onDismissed: (direction) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text("${habits[index].title} was dismissed")) ); habits.removeAt(index); print("Das Widget wurde gelöscht: ${habits[index].title}"); }, 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"); } }, ), ), ), ), ); }, ); } }