table_calendar icon indicating copy to clipboard operation
table_calendar copied to clipboard

if the day has more than one event , only the latest added event will be shown .

Open shifo-stack opened this issue 1 year ago • 0 comments

Describe the bug I get my events from API to display it in the calendar , the getHashCode method replace the events of the same day , so if the day has more than one event , only the latest added event will be shown , and when I try to modify the method to get unique hashcode for every element no events is displayed in the calendar although all events are in the kEvents LinkedHashMap .

here's an example with fake API

Future<List<Event>> getDataFromWeb() async { var data = await http.get(Uri.parse( "https://js.syncfusion.com/demos/ejservices/api/Schedule/LoadData")); var jsonData = json.decode(data.body); for (var data in jsonData) { Event meetingData = Event( eventName: data['Subject'], startTime: kToday, endTime: kToday, ); eventsList.add(meetingData); } final Map<DateTime, List<Event>> kEventSource = Map.fromIterable( eventsList, key: (item) => item.startTime, value: (item) => [item], ); _kEventSource.addAll(kEventSource); kEvents.addAll(_kEventSource); return eventsList; }

final kEvents = LinkedHashMap<DateTime, List<Event>>( equals: isSameDay, hashCode: getHashCode, )..addAll(_kEventSource);

final Map<DateTime, List<Event>> _kEventSource = Map.fromIterable(eventsList, key: (item) => DateTime.utc( item.startTime.year, item.startTime.month, item.startTime.day, ), value: (item) => List.generate( item % 4 + 1, (index) => Event(eventName: item.eventName)));

int getHashCode(DateTime key) { return key.hashCode; }

shifo-stack avatar Apr 21 '23 14:04 shifo-stack