From 43c4f4e6faa9183e64070d7ada1ebb09d6523b18 Mon Sep 17 00:00:00 2001 From: Cxx0822 <1556464090@qq.com> Date: Wed, 29 Apr 2026 19:53:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=97=A5=E7=A8=8B?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/schedule_page.dart | 133 ++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 63 deletions(-) diff --git a/lib/pages/schedule_page.dart b/lib/pages/schedule_page.dart index 26c62d5..4d74359 100644 --- a/lib/pages/schedule_page.dart +++ b/lib/pages/schedule_page.dart @@ -23,23 +23,23 @@ class _SchedulePageState extends State { late List _appointments = []; String _viewType = 'week'; - void _addSchedule() { + void _addSchedule(Schedule? schedule) { showDialog( context: context, - builder: - (context) => ScheduleDialog( - onSave: (schedule) { - setState(() { - final appointment = calendar.Appointment( - id: schedule.id, - subject: schedule.title, - startTime: schedule.startTime, - endTime: schedule.endTime, - ); - _appointments.add(appointment); - }); - }, - ), + builder: (context) => ScheduleDialog( + schedule: schedule, + onSave: (schedule) { + setState(() { + final appointment = calendar.Appointment( + id: schedule.id, + subject: schedule.title, + startTime: schedule.startTime, + endTime: schedule.endTime, + ); + _appointments.add(appointment); + }); + }, + ), ); } @@ -53,52 +53,52 @@ class _SchedulePageState extends State { showDialog( context: context, - builder: - (context) => ScheduleDialog( - schedule: schedule, - onSave: (editedSchedule) { - setState(() { - final index = _appointments.indexWhere( - (t) => t.id == editedSchedule.id, - ); - if (index != -1) { - final appointment = calendar.Appointment( - id: editedSchedule.id, - subject: editedSchedule.title, - startTime: editedSchedule.startTime, - endTime: editedSchedule.endTime, - ); - _appointments[index] = appointment; - } - }); - }, - ), + builder: (context) => ScheduleDialog( + schedule: schedule, + onSave: (editedSchedule) { + setState(() { + final index = _appointments.indexWhere( + (t) => t.id == editedSchedule.id, + ); + if (index != -1) { + final appointment = calendar.Appointment( + id: editedSchedule.id, + subject: editedSchedule.title, + startTime: editedSchedule.startTime, + endTime: editedSchedule.endTime, + ); + _appointments[index] = appointment; + } + }); + }, + ), ); } void _deleteSchedule(calendar.Appointment appointment) async { await showDialog( context: context, - builder: - (context) => ContentDialog( - title: const Text('确认删除该日程?'), - actions: [ - Button( - child: const Text('取消'), - onPressed: () => Navigator.pop(context), - ), - FilledButton( - child: const Text('确认'), - onPressed: () { - setState(() { - _appointments.removeWhere((schedule) => schedule.id == appointment.id); - }); - Navigator.pop(context); - // Delete file here - }, - ) - ], + builder: (context) => ContentDialog( + title: const Text('确认删除该日程?'), + actions: [ + Button( + child: const Text('取消'), + onPressed: () => Navigator.pop(context), ), + FilledButton( + child: const Text('确认'), + onPressed: () { + setState(() { + _appointments.removeWhere( + (schedule) => schedule.id == appointment.id, + ); + }); + Navigator.pop(context); + // Delete file here + }, + ), + ], + ), ); } @@ -113,7 +113,7 @@ class _SchedulePageState extends State { CommandBarButton( icon: const Icon(FluentIcons.add), label: const Text('添加日程'), - onPressed: _addSchedule, + onPressed: () => _addSchedule(null), ), ], ), @@ -209,14 +209,21 @@ class _SchedulePageState extends State { ), // 选择日期回调 onTap: (calendar.CalendarTapDetails details) { - if (details.targetElement == calendar.CalendarElement.calendarCell) { - if (!details.date!.isBefore(DateTime.now())) { - _addSchedule(); - } - } else if (details.targetElement == - calendar.CalendarElement.appointment) { - if (details.appointments?.length == 1) { - _editSchedule(details.appointments!.first); + if (_calendarController.view == calendar.CalendarView.week) { + if (details.targetElement == calendar.CalendarElement.calendarCell) { + if (!details.date!.isBefore(DateTime.now())) { + final schedule = Schedule( + title: '', + startTime: details.date!, + endTime: details.date!.add(Duration(minutes: 30)), + ); + _addSchedule(schedule); + } + } else if (details.targetElement == + calendar.CalendarElement.appointment) { + if (details.appointments?.length == 1) { + _editSchedule(details.appointments!.first); + } } } },