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][1]), 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][1]} was dismissed")) ); habits.removeAt(index); print("Das Widget wurde gelöscht: ${habits[index][1]}"); }, child: ListTile( title: Text(habits[index][1]), subtitle: Text(habits[index][2]), trailing: habits[index][3], leading: Checkbox( value: habits[index][0], onChanged: (value) { if (value == false) { print("decrease counter"); } else { print("increase counter"); } }, ), ), ), ), ); }, ); } }