Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
feat: 날짜, 완료 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
suu3 committed Jul 2, 2024
1 parent 4a710a0 commit 799ca9e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
17 changes: 17 additions & 0 deletions lib/providers/task_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand All @@ -25,4 +27,19 @@ class TaskListNotifier extends StateNotifier<List<Task>> {
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],
];
}
}
37 changes: 33 additions & 4 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> taskData = {'title': '', 'description': ''};
final Map<String, String> taskData = {
'title': '',
'description': '',
'dateTime': ''
};

void addTask() {
ref.read(taskListProvider.notifier).addTask(
Expand Down Expand Up @@ -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,
),
),
),
),
Expand Down
33 changes: 32 additions & 1 deletion lib/widgets/add_task_bottomsheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ class AddTaskBottomSheet extends ConsumerWidget {
required this.onPressed,
});

Future<void> _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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 799ca9e

Please sign in to comment.