createEvent function

Future<bool> createEvent(
  1. EventNotificationModel eventData
)

Implementation

Future<bool> createEvent(EventNotificationModel eventData) async {
  // ignore: unnecessary_null_comparison
  if (eventData == null) {
    throw Exception('Event cannot be null');
  }
  if (eventData.atsignCreator == null ||
      eventData.atsignCreator!.trim().isEmpty) {
    throw Exception('Event creator cannot be empty');
  }

  if (eventData.group!.members!.isEmpty) {
    throw Exception('No members found');
  }

  eventData.key = 'createevent-${DateTime.now().microsecondsSinceEpoch}';

  try {
    var atKey = AtKey()
      ..metadata = Metadata()
      ..metadata!.ttr = -1
      ..key = eventData.key
      ..sharedWith = eventData.group!.members!.elementAt(0).atSign
      ..sharedBy = eventData.atsignCreator;
    var eventJson =
        EventNotificationModel.convertEventNotificationToJson(eventData);
    var result = await EventService().atClientInstance!.put(atKey, eventJson);
    return result;
  } catch (e) {
    print('error in creating event:$e');
    return false;
  }
}