getEventList method

  1. @override
Future<List<MobkitCalendarAppointmentModel>> getEventList(
  1. Map arguments
)
override

Implementation

@override
Future<List<MobkitCalendarAppointmentModel>> getEventList(
    Map arguments) async {
  // ignore: deprecated_member_use
  PermissionStatus result = await Permission.calendar.request();
  List<MobkitCalendarAppointmentModel> events = [];
  if ((arguments["idlist"] is List<String>) &&
      result.isGranted &&
      (arguments["idlist"] as List<String>).isNotEmpty) {
    String? eventList =
        await methodChannel.invokeMethod<String?>('getEventList', arguments);
    Map eventMap = json.decode(eventList ?? "");
    if (eventMap["events"] is List<Object?>) {
      for (var event in eventMap["events"]) {
        if (event is Map) {
          late MobkitCalendarAppointmentModel mobkitCalendarAppointmentModel;
          if (Platform.isAndroid) {
            mobkitCalendarAppointmentModel = MobkitCalendarAppointmentModel(
              nativeEventId: event["nativeEventId"].toString(),
              title: event["fullName"],
              appointmentStartDate: DateTime.fromMillisecondsSinceEpoch(
                  event["startDate"],
                  isUtc: event["isFullDayEvent"]),
              appointmentEndDate: DateTime.fromMillisecondsSinceEpoch(
                  event["endDate"],
                  isUtc: event["isFullDayEvent"]),
              isAllDay: event["isFullDayEvent"],
              detail: event["description"] ?? "",
              color: const Color(0xff7209b7),
              recurrenceModel: null,
            );
          } else {
            mobkitCalendarAppointmentModel = MobkitCalendarAppointmentModel(
              nativeEventId: event["nativeEventId"].toString(),
              title: event["fullName"],
              appointmentStartDate:
                  DateFormat('dd/MM/yyyy HH:mm:ss').parse(event["startDate"]),
              appointmentEndDate:
                  DateFormat('dd/MM/yyyy HH:mm:ss').parse(event["endDate"]),
              isAllDay: event["isFullDayEvent"],
              detail: event["description"] ?? "",
              color: const Color(0xff7209b7),
              recurrenceModel: null,
            );
          }
          events.add(mobkitCalendarAppointmentModel);
        }
      }
    }
  }
  return events;
}