diff --git a/lib/providers/task_provider.dart b/lib/providers/task_provider.dart index 97c050b..0c58d0b 100644 --- a/lib/providers/task_provider.dart +++ b/lib/providers/task_provider.dart @@ -9,11 +9,13 @@ class Task { final String title; final String description; final DateTime dateTime; + bool isCompleted; Task({ required this.title, required this.description, required this.dateTime, + this.isCompleted = false, }); } @@ -25,4 +27,19 @@ class TaskListNotifier extends StateNotifier> { Task(title: title, description: description, dateTime: DateTime.now()); state = [...state, newTask]; } + + void toggleTaskCompletion(int index) { + state = [ + for (int i = 0; i < state.length; i++) + if (i == index) + Task( + title: state[i].title, + description: state[i].description, + dateTime: state[i].dateTime, + isCompleted: !state[i].isCompleted, + ) + else + state[i], + ]; + } } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index fd1f2d9..45e2451 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -11,7 +11,11 @@ class MyHome extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final theme = Theme.of(context); final taskList = ref.watch(taskListProvider); - final Map taskData = {'title': '', 'description': ''}; + final Map taskData = { + 'title': '', + 'description': '', + 'dateTime': '' + }; void addTask() { ref.read(taskListProvider.notifier).addTask( @@ -49,10 +53,35 @@ class MyHome extends ConsumerWidget { const EdgeInsets.symmetric(vertical: 3, horizontal: 16), child: Card( child: ListTile( - leading: const Icon(Icons.radio_button_unchecked), - title: Text(task.title), + leading: IconButton( + icon: Icon( + task.isCompleted + ? Icons.check_circle + : Icons.radio_button_unchecked, + color: task.isCompleted ? Colors.green : null, + ), + onPressed: () { + ref + .read(taskListProvider.notifier) + .toggleTaskCompletion(index); + }, + ), + title: Text( + task.title, + style: TextStyle( + decoration: task.isCompleted + ? TextDecoration.lineThrough + : null, + color: task.isCompleted ? Colors.grey : null, + ), + ), subtitle: Text( - task.description, + '${task.description}\n${task.dateTime.month}월 ${task.dateTime.day}일 까지', + style: TextStyle( + color: task.isCompleted + ? Colors.grey.withOpacity(0.5) + : null, + ), ), ), ), diff --git a/lib/widgets/add_task_bottomsheet.dart b/lib/widgets/add_task_bottomsheet.dart index bc27320..a1873f0 100644 --- a/lib/widgets/add_task_bottomsheet.dart +++ b/lib/widgets/add_task_bottomsheet.dart @@ -11,6 +11,32 @@ class AddTaskBottomSheet extends ConsumerWidget { required this.onPressed, }); + Future _selectDate(BuildContext context) async { + final DateTime? picked = await showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime(2000), + lastDate: DateTime(2101), + builder: (context, child) { + return Theme( + data: ThemeData.dark().copyWith( + colorScheme: ColorScheme.dark( + primary: Colors.purple, // Header background color + onPrimary: Colors.white, // Header text color + surface: Colors.grey[800]!, // Background color of the calendar + onSurface: Colors.white, // Text color + ), + dialogBackgroundColor: Colors.black, + ), + child: child!, + ); + }, + ); + if (picked != null) { + taskData['dateTime'] = picked.toIso8601String(); // Save the selected date + } + } + @override Widget build(BuildContext context, WidgetRef ref) { return Container( @@ -56,7 +82,12 @@ class AddTaskBottomSheet extends ConsumerWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - // Icon(Icons.timer, size: 30), + IconButton( + icon: const Icon(Icons.calendar_today, size: 30), + onPressed: () { + _selectDate(context); + }, + ), // Icon(Icons.location_on, size: 30), // Icon(Icons.flag, size: 30), IconButton(