addOrEditCalendarEvent method

  1. @override
Future<({String? eventId, ResultType resultType})> addOrEditCalendarEvent(
  1. BuildContext context, {
  2. String? calendarId,
  3. String? eventId,
  4. String? title,
  5. String? description,
  6. int? startDate,
  7. int? endDate,
  8. bool? allDay,
})
override

Implementation

@override
Future<({ResultType resultType, String? eventId})> addOrEditCalendarEvent(BuildContext context, {String? calendarId, String? eventId, String? title, String? description, int? startDate, int? endDate, bool?  allDay}) async {
  if (Platform.isAndroid) {
    if (((await DeviceCalendarPlugin().hasPermissions()).data == true || (await DeviceCalendarPlugin().requestPermissions()).data == true) && context.mounted) {
      var result = await EditCalendarEventPage.show(context, calendarId: calendarId, eventId: eventId, title: title, description: description, startDate: startDate, endDate: endDate, allDay: allDay);
      return result as ({ResultType resultType, String? eventId})? ?? (resultType: ResultType.canceled, eventId: eventId);
    } else {
      return  (resultType: ResultType.canceled, eventId: eventId);
    }

  } else {
    final result = await methodChannel.invokeMethod<String?>(
      'addOrEditCalendarEvent',
      {
        'calendarId': calendarId,
        'eventId': eventId,
        'title': title,
        'description': description,
        'startDate': startDate,
        'endDate': endDate,
        'allDay': allDay,
      },
    );
    if (result == null) {
      return (resultType: ResultType.canceled, eventId: eventId);
    } else if (result == "deleted") {
      return (resultType: ResultType.deleted, eventId: eventId);
    } else {
      return (resultType: ResultType.saved, eventId: result);
    }
  }
}