createEvent function
This method creates an event by storing event data in a remote database It checks for the validity of the input data and throws exceptions if it's invalid If the event creation is successful, it returns true; otherwise, it returns false
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().atClientManager.atClient.put(atKey, eventJson);
return result;
} catch (e) {
print('error in creating event:$e');
return false;
}
}