addEvent static method
Implementation
static Future<void> addEvent(BuildContext context,
{required Event event,
Function? onPermissionDenied,
Function? onError,
Function? onSubmitted,
String? dialogBoxTitle}) async {
try {
if (Platform.isAndroid) {
List calendars = await _channel.invokeMethod('getCalendarList');
List<DeviceCalendar> modelList = calendars
.map((map) => DeviceCalendar.fromMap(_convertMap(map)))
.toList();
if (modelList.length == 1) {
String createdEventId = await _addEventToCalendar(
event: event, calendarId: modelList.first.id);
if (onSubmitted != null) {
onSubmitted(createdEventId);
}
} else {
_showCalendarsListDialog(
context: context,
calendars: modelList,
onCalendarSelected: (id) async {
String createdEventId =
await _addEventToCalendar(event: event, calendarId: id);
if (onSubmitted != null) {
onSubmitted(createdEventId);
}
});
}
} else {
String createdEventId =
await _addEventToCalendar(event: event, calendarId: "0");
if (onSubmitted != null) {
onSubmitted(createdEventId);
}
}
} catch (e) {
debugPrint("Error: $e");
if (onError != null) {
onError();
}
}
}