import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/todo_provider.dart'; import '../widgets/todo_form.dart'; class ToDoListScreen extends StatelessWidget { @override Widget build(BuildContext context) { var todoProvider = Provider.of(context); // Helper function to format DateTime String formatDate(DateTime date) { return '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}'; } return Scaffold( appBar: AppBar( title: Text('To-Do list'), actions: [ // Filter Dropdown MenĂ¼ PopupMenuButton( onSelected: (value) { switch (value) { case 'Deadline': todoProvider.sortByDeadline(); break; case 'Priority': todoProvider.sortByPriority(); break; case 'Status': todoProvider.sortByStatus(); break; case 'None': break; } }, itemBuilder: (BuildContext context) { return {'Deadline', 'Priority', 'Status', 'None'}.map((String choice) { return PopupMenuItem( value: choice, child: Text(choice), ); }).toList(); }, ), ], ), body: Column( children: [ Expanded( child: ListView.builder( itemCount: todoProvider.todos.length, itemBuilder: (context, index) { var todo = todoProvider.todos[index]; String formattedDate = formatDate(todo.deadline); // Formatierung des Datums return ListTile( title: Text( todo.title, style: TextStyle( decoration: todo.isCompleted ? TextDecoration.lineThrough : TextDecoration.none, ), ), subtitle: Text('Due: $formattedDate | ${todo.priority} priority'), trailing: Row( mainAxisSize: MainAxisSize.min, children: [ Checkbox( value: todo.isCompleted, onChanged: (value) { todoProvider.toggleCompletion(index); }, ), IconButton( icon: Icon(Icons.close), onPressed: () => todoProvider.removeTask(index), ), ], ), ); }, ), ), ], ), floatingActionButton: FloatingActionButton( onPressed: () { showModalBottomSheet( context: context, isScrollControlled: true, builder: (BuildContext context) { return Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom, ), child: ToDoForm(), ); }, ); }, child: Icon(Icons.add), ), ); } }