feat:增加日程自动添加时间功能

This commit is contained in:
2026-04-29 19:53:37 +08:00
parent 0e6fe4ad4b
commit 43c4f4e6fa

View File

@@ -23,11 +23,11 @@ class _SchedulePageState extends State<SchedulePage> {
late List<calendar.Appointment> _appointments = []; late List<calendar.Appointment> _appointments = [];
String _viewType = 'week'; String _viewType = 'week';
void _addSchedule() { void _addSchedule(Schedule? schedule) {
showDialog( showDialog(
context: context, context: context,
builder: builder: (context) => ScheduleDialog(
(context) => ScheduleDialog( schedule: schedule,
onSave: (schedule) { onSave: (schedule) {
setState(() { setState(() {
final appointment = calendar.Appointment( final appointment = calendar.Appointment(
@@ -53,8 +53,7 @@ class _SchedulePageState extends State<SchedulePage> {
showDialog( showDialog(
context: context, context: context,
builder: builder: (context) => ScheduleDialog(
(context) => ScheduleDialog(
schedule: schedule, schedule: schedule,
onSave: (editedSchedule) { onSave: (editedSchedule) {
setState(() { setState(() {
@@ -79,8 +78,7 @@ class _SchedulePageState extends State<SchedulePage> {
void _deleteSchedule(calendar.Appointment appointment) async { void _deleteSchedule(calendar.Appointment appointment) async {
await showDialog<String>( await showDialog<String>(
context: context, context: context,
builder: builder: (context) => ContentDialog(
(context) => ContentDialog(
title: const Text('确认删除该日程?'), title: const Text('确认删除该日程?'),
actions: [ actions: [
Button( Button(
@@ -91,12 +89,14 @@ class _SchedulePageState extends State<SchedulePage> {
child: const Text('确认'), child: const Text('确认'),
onPressed: () { onPressed: () {
setState(() { setState(() {
_appointments.removeWhere((schedule) => schedule.id == appointment.id); _appointments.removeWhere(
(schedule) => schedule.id == appointment.id,
);
}); });
Navigator.pop(context); Navigator.pop(context);
// Delete file here // Delete file here
}, },
) ),
], ],
), ),
); );
@@ -113,7 +113,7 @@ class _SchedulePageState extends State<SchedulePage> {
CommandBarButton( CommandBarButton(
icon: const Icon(FluentIcons.add), icon: const Icon(FluentIcons.add),
label: const Text('添加日程'), label: const Text('添加日程'),
onPressed: _addSchedule, onPressed: () => _addSchedule(null),
), ),
], ],
), ),
@@ -209,9 +209,15 @@ class _SchedulePageState extends State<SchedulePage> {
), ),
// 选择日期回调 // 选择日期回调
onTap: (calendar.CalendarTapDetails details) { onTap: (calendar.CalendarTapDetails details) {
if (_calendarController.view == calendar.CalendarView.week) {
if (details.targetElement == calendar.CalendarElement.calendarCell) { if (details.targetElement == calendar.CalendarElement.calendarCell) {
if (!details.date!.isBefore(DateTime.now())) { if (!details.date!.isBefore(DateTime.now())) {
_addSchedule(); final schedule = Schedule(
title: '',
startTime: details.date!,
endTime: details.date!.add(Duration(minutes: 30)),
);
_addSchedule(schedule);
} }
} else if (details.targetElement == } else if (details.targetElement ==
calendar.CalendarElement.appointment) { calendar.CalendarElement.appointment) {
@@ -219,6 +225,7 @@ class _SchedulePageState extends State<SchedulePage> {
_editSchedule(details.appointments!.first); _editSchedule(details.appointments!.first);
} }
} }
}
}, },
// 选择日程回调 // 选择日程回调
onLongPress: (calendar.CalendarLongPressDetails details) async { onLongPress: (calendar.CalendarLongPressDetails details) async {