feat:增加日程自动添加时间功能
This commit is contained in:
@@ -23,23 +23,23 @@ class _SchedulePageState extends State<SchedulePage> {
|
||||
late List<calendar.Appointment> _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<SchedulePage> {
|
||||
|
||||
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<String>(
|
||||
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<SchedulePage> {
|
||||
CommandBarButton(
|
||||
icon: const Icon(FluentIcons.add),
|
||||
label: const Text('添加日程'),
|
||||
onPressed: _addSchedule,
|
||||
onPressed: () => _addSchedule(null),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -209,14 +209,21 @@ class _SchedulePageState extends State<SchedulePage> {
|
||||
),
|
||||
// 选择日期回调
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user