2024-10-22 10:38:22 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../buisness/ToDoItem.dart';
|
|
|
|
import '../buisness/ToDoProvider.dart';
|
|
|
|
|
|
|
|
class ToDoExpandableWidget extends StatelessWidget {
|
|
|
|
final ToDoItem toDoItem;
|
2024-10-29 13:13:10 +01:00
|
|
|
final int id;
|
2024-10-22 10:38:22 +02:00
|
|
|
|
2024-10-30 23:41:56 +01:00
|
|
|
getStatusColor(String status) {
|
|
|
|
switch(status) {
|
|
|
|
case 'Pending':
|
|
|
|
return Colors.blueGrey;
|
|
|
|
case 'In Progress':
|
|
|
|
return Colors.lime;
|
|
|
|
case 'Completed':
|
|
|
|
return Colors.green;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-22 10:38:22 +02:00
|
|
|
const ToDoExpandableWidget({
|
2024-10-29 19:06:41 +01:00
|
|
|
super.key,
|
2024-10-22 10:38:22 +02:00
|
|
|
required this.toDoItem,
|
2024-10-29 13:13:10 +01:00
|
|
|
required this.id,
|
2024-10-29 19:06:41 +01:00
|
|
|
});
|
2024-10-22 10:38:22 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
2024-10-30 23:41:56 +01:00
|
|
|
color: getStatusColor(toDoItem.status),
|
|
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
|
|
|
2024-10-22 10:38:22 +02:00
|
|
|
child: ExpansionTile(
|
2024-10-29 19:06:41 +01:00
|
|
|
title: Text(toDoItem.name, style: const TextStyle(color: Colors.black)),
|
2024-10-22 10:38:22 +02:00
|
|
|
subtitle: Text('Due: ${toDoItem.dueDate.toLocal()}'),
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-10-30 23:41:56 +01:00
|
|
|
Text(toDoItem.description, style: const TextStyle(color: Colors.black)),
|
2024-10-29 19:06:41 +01:00
|
|
|
const SizedBox(height: 10),
|
2024-10-22 10:38:22 +02:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2024-10-30 23:41:56 +01:00
|
|
|
TextButton.icon(
|
2024-10-29 19:06:41 +01:00
|
|
|
onPressed: () {
|
|
|
|
Provider.of<ToDoProvider>(context, listen: false).deleteItem(toDoItem.id!);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.delete),
|
|
|
|
label: const Text("Delete"),
|
|
|
|
style: ElevatedButton.styleFrom(
|
2024-10-30 23:41:56 +01:00
|
|
|
foregroundColor: const Color(0xFFBB0000),
|
|
|
|
backgroundColor: getStatusColor(toDoItem.status),
|
2024-10-29 19:06:41 +01:00
|
|
|
textStyle: const TextStyle(fontSize: 15),
|
2024-10-30 23:41:56 +01:00
|
|
|
iconColor: const Color(0xFFBB0000),
|
2024-10-29 19:06:41 +01:00
|
|
|
),
|
|
|
|
),
|
2024-10-30 23:41:56 +01:00
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: getStatusColor(toDoItem.status),
|
|
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
|
|
),
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: DropdownButton<String>(
|
|
|
|
value: toDoItem.status,
|
|
|
|
items: ['Pending', 'In Progress', 'Completed']
|
|
|
|
.map((status) => DropdownMenuItem(
|
|
|
|
value: status,
|
|
|
|
child: Text(status),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
dropdownColor: getStatusColor(toDoItem.status),
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value != null) {
|
|
|
|
Provider.of<ToDoProvider>(context, listen: false).updateStatus(id, value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2024-10-22 10:38:22 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|