cpd/lib/widgets/listview.dart

59 lines
2.0 KiB
Dart
Raw Normal View History

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(
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(
SnackBar(content: Text("${habits[index].title} was dismissed"))
2024-05-09 09:46:23 +02:00
);
habits.removeAt(index);
print("Das Widget wurde gelöscht: ${habits[index].title}");
2024-05-09 09:46:23 +02:00
},
child: ListTile(
title: Text(habits[index].title),
subtitle: Text(habits[index].subtitle ?? ''),
trailing: habits[index].icon,
2024-05-09 09:46:23 +02:00
leading: Checkbox(
value: habits[index].isComplete,
2024-05-09 09:46:23 +02:00
onChanged: (value) {
if (value == false) {
print("decrease counter");
} else {
print("increase counter");
}
},
),
),
),
),
);
},
);
}
}