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 {
|
|
|
|
@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(
|
|
|
|
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(
|
2024-05-09 17:37:41 +02:00
|
|
|
SnackBar(content: Text("${habits[index].title} was dismissed"))
|
2024-05-09 09:46:23 +02:00
|
|
|
);
|
|
|
|
habits.removeAt(index);
|
2024-05-09 17:37:41 +02:00
|
|
|
print("Das Widget wurde gelöscht: ${habits[index].title}");
|
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");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|