How to drop the appointment based on the time interval in Flutter Calendar?
In the Flutter Event Calendar, you can drop the appointments to the particular timeslots by using the onDragEnd callback of the Flutter Calendar.
STEP 1: In initState(), initialize the default values for the calendar.
late _DataSource _events; @override void initState() { _events = _addAppointments(); super.initState(); }
STEP 2: Using the dragEnd callback of the Flutter Calendar, find the difference between the start and end time of the appointment. Then set the start time for the appointment based on the appointment drag end details.
void _dragEnd(AppointmentDragEndDetails appointmentDragEndDetails) { Appointment detail = appointmentDragEndDetails.appointment as Appointment; Duration = detail.endTime.difference(detail.startTime); DateTime start = DateTime( appointmentDragEndDetails.droppingTime!.year, appointmentDragEndDetails.droppingTime!.month, appointmentDragEndDetails.droppingTime!.day, appointmentDragEndDetails.droppingTime!.hour, 0, 0); final List<Appointment> appointment = <Appointment>[]; _events.appointments!.remove(appointmentDragEndDetails.appointment); /// No direct support for drop the appointment to specified time intervals. So, remove the dragged appointment add /// new appointment with specified timing for dropping. _events.notifyListeners(CalendarDataSourceAction.remove, <dynamic>[appointmentDragEndDetails.appointment]); Appointment app = Appointment( subject: detail.subject, color: detail.color, startTime: start, endTime: start.add(duration), ); appointment.add(app); _events.appointments!.add(appointment[0]); _events.notifyListeners(CalendarDataSourceAction.add, appointment); }
STEP 3: Assign those _dragEnd to the dragEnd callback of the calendar.
child: SfCalendar( allowedViews: const [ CalendarView.day, CalendarView.week, CalendarView.workWeek, CalendarView.timelineDay, CalendarView.timelineWeek, CalendarView.timelineWorkWeek, CalendarView.schedule, ], dataSource: _events, allowDragAndDrop: true, onDragEnd: _dragEnd, ),
Conclusion
I hope you enjoyed learning about how to drop the appointment based on the time interval in Flutter Calendar.
You can refer to our Flutter Calender feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter Calendar documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!