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 = [];
String _viewType = 'week';
void _addSchedule() {
void _addSchedule(Schedule? schedule) {
showDialog(
context: context,
builder:
(context) => ScheduleDialog(
builder: (context) => ScheduleDialog(
schedule: schedule,
onSave: (schedule) {
setState(() {
final appointment = calendar.Appointment(
@@ -53,8 +53,7 @@ class _SchedulePageState extends State<SchedulePage> {
showDialog(
context: context,
builder:
(context) => ScheduleDialog(
builder: (context) => ScheduleDialog(
schedule: schedule,
onSave: (editedSchedule) {
setState(() {
@@ -79,8 +78,7 @@ class _SchedulePageState extends State<SchedulePage> {
void _deleteSchedule(calendar.Appointment appointment) async {
await showDialog<String>(
context: context,
builder:
(context) => ContentDialog(
builder: (context) => ContentDialog(
title: const Text('确认删除该日程?'),
actions: [
Button(
@@ -91,12 +89,14 @@ class _SchedulePageState extends State<SchedulePage> {
child: const Text('确认'),
onPressed: () {
setState(() {
_appointments.removeWhere((schedule) => schedule.id == appointment.id);
_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,9 +209,15 @@ class _SchedulePageState extends State<SchedulePage> {
),
// 选择日期回调
onTap: (calendar.CalendarTapDetails details) {
if (_calendarController.view == calendar.CalendarView.week) {
if (details.targetElement == calendar.CalendarElement.calendarCell) {
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 ==
calendar.CalendarElement.appointment) {
@@ -219,6 +225,7 @@ class _SchedulePageState extends State<SchedulePage> {
_editSchedule(details.appointments!.first);
}
}
}
},
// 选择日程回调
onLongPress: (calendar.CalendarLongPressDetails details) async {