JonasWanke/timetable

Draggable events with custom eventProvider

Opened this issue · 4 comments

How can we use our own eventProvider and make events draggable? @JonasWanke from example you provided I've done small changes to class that extends BasicEvent class _DemoEvent extends BasicEvent {:

class EventModel extends BasicEvent {
  final CalendarEventDTO eventData;

  EventModel(
    this.eventData, {
  }) : super(
          id: eventData.id!,
          title: eventData.title!,
          backgroundColor: Color(
              int.parse(eventData.backgroundColor!.replaceAll('#', '0xff'))),
          start: eventData.startDateTime.toUtc(),
          end: eventData.endDateTime.toUtc(),
        );


  @override
  EventModel copyWith(
      {CalendarEventDTO? eventData,
      Object? id,
      String? title,
      Color? backgroundColor,
      bool? showOnTop,
      DateTime? start,
      DateTime? end}) {
    return EventModel(eventData ?? this.eventData);
  }

The issue I run into is when I try to long press any event to drag it over timetable it does not work. Event does get expanded but it does not move as I drag finger across screen, although it does detect new date where i dropped event, it just does not show it as i drag it over screen:

I believe relevant code for this is from example project inside main.dart, timeOverlayProvider

Code:

timeOverlayProvider: mergeTimeOverlayProviders([
  positioningDemoOverlayProvider,
  (context, date) => _draggedEvents
      .map((it) =>
          it.toTimeOverlay(date: date, widget: BasicEventWidget(it)))
      .whereNotNull()
      .toList(),
]),
Recording.21.mp4

If you want to display the event while it's being dragged, you have to somehow supply it to Timetable. The snippet you referenced is the relevant part and implements it using time overlays. You have to adapt that your event.

If you want to display the event while it's being dragged, you have to somehow supply it to Timetable. The snippet you referenced is the relevant part and implements it using time overlays. You have to adapt that your event.

I am confused what exactly should i change in that snippet code because I don't quite understand why it doesn't work since I use extended BasicEvent in Timetable and all i have added in that extension is one field:

class EventModel extends BasicEvent {
  final CalendarEventDTO eventData

If the above snippet is still in your code and produces time overlays, then it should work. Otherwise, please post your code for reproducing the issue you're encountering

It works as expected, I did not provided events correctly that is why i had isuses