feat:增加日程自动添加时间功能
This commit is contained in:
@@ -23,23 +23,23 @@ 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(
|
||||||
id: schedule.id,
|
id: schedule.id,
|
||||||
subject: schedule.title,
|
subject: schedule.title,
|
||||||
startTime: schedule.startTime,
|
startTime: schedule.startTime,
|
||||||
endTime: schedule.endTime,
|
endTime: schedule.endTime,
|
||||||
);
|
);
|
||||||
_appointments.add(appointment);
|
_appointments.add(appointment);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,52 +53,52 @@ 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(() {
|
final index = _appointments.indexWhere(
|
||||||
final index = _appointments.indexWhere(
|
(t) => t.id == editedSchedule.id,
|
||||||
(t) => t.id == editedSchedule.id,
|
);
|
||||||
);
|
if (index != -1) {
|
||||||
if (index != -1) {
|
final appointment = calendar.Appointment(
|
||||||
final appointment = calendar.Appointment(
|
id: editedSchedule.id,
|
||||||
id: editedSchedule.id,
|
subject: editedSchedule.title,
|
||||||
subject: editedSchedule.title,
|
startTime: editedSchedule.startTime,
|
||||||
startTime: editedSchedule.startTime,
|
endTime: editedSchedule.endTime,
|
||||||
endTime: editedSchedule.endTime,
|
);
|
||||||
);
|
_appointments[index] = appointment;
|
||||||
_appointments[index] = appointment;
|
}
|
||||||
}
|
});
|
||||||
});
|
},
|
||||||
},
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
child: const Text('取消'),
|
||||||
child: const Text('取消'),
|
onPressed: () => Navigator.pop(context),
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
child: const Text('确认'),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_appointments.removeWhere((schedule) => schedule.id == appointment.id);
|
|
||||||
});
|
|
||||||
Navigator.pop(context);
|
|
||||||
// Delete file here
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
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(
|
CommandBarButton(
|
||||||
icon: const Icon(FluentIcons.add),
|
icon: const Icon(FluentIcons.add),
|
||||||
label: const Text('添加日程'),
|
label: const Text('添加日程'),
|
||||||
onPressed: _addSchedule,
|
onPressed: () => _addSchedule(null),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -209,14 +209,21 @@ class _SchedulePageState extends State<SchedulePage> {
|
|||||||
),
|
),
|
||||||
// 选择日期回调
|
// 选择日期回调
|
||||||
onTap: (calendar.CalendarTapDetails details) {
|
onTap: (calendar.CalendarTapDetails details) {
|
||||||
if (details.targetElement == calendar.CalendarElement.calendarCell) {
|
if (_calendarController.view == calendar.CalendarView.week) {
|
||||||
if (!details.date!.isBefore(DateTime.now())) {
|
if (details.targetElement == calendar.CalendarElement.calendarCell) {
|
||||||
_addSchedule();
|
if (!details.date!.isBefore(DateTime.now())) {
|
||||||
}
|
final schedule = Schedule(
|
||||||
} else if (details.targetElement ==
|
title: '',
|
||||||
calendar.CalendarElement.appointment) {
|
startTime: details.date!,
|
||||||
if (details.appointments?.length == 1) {
|
endTime: details.date!.add(Duration(minutes: 30)),
|
||||||
_editSchedule(details.appointments!.first);
|
);
|
||||||
|
_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