Event.fromJson constructor

Event.fromJson(
  1. Map<String, dynamic>? json
)

Implementation

Event.fromJson(Map<String, dynamic>? json) {
  if (json == null) {
    throw ArgumentError(ErrorMessages.fromJsonMapIsNull);
  }

  eventId = json['eventId'];
  calendarId = json['calendarId'];
  title = json['title'];
  description = json['description'];
  int? startMillisecondsSinceEpoch = json['start'];
  if (startMillisecondsSinceEpoch != null) {
    start = DateTime.fromMillisecondsSinceEpoch(startMillisecondsSinceEpoch);
  }
  int? endMillisecondsSinceEpoch = json['end'];
  if (endMillisecondsSinceEpoch != null) {
    end = DateTime.fromMillisecondsSinceEpoch(endMillisecondsSinceEpoch);
  }
  startTimeZone = json['startTimeZone'];
  endTimeZone = json['endTimeZone'];
  allDay = json['allDay'];
  location = json['location'];
  availability = parseStringToAvailability(json['availability']);

  var foundUrl = json['url']?.toString();
  if (foundUrl?.isEmpty ?? true) {
    url = null;
  } else {
    url = Uri.dataFromString(foundUrl as String);
  }

  if (json['attendees'] != null) {
    attendees = json['attendees'].map<Attendee>((decodedAttendee) {
      return Attendee.fromJson(decodedAttendee);
    }).toList();
  }
  if (json['recurrenceRule'] != null) {
    recurrenceRule = RecurrenceRule.fromJson(json['recurrenceRule']);
  }
  if (json['organizer'] != null) {
    // Getting and setting an organiser for iOS
    var organiser = Attendee.fromJson(json['organizer']);

    var attendee = attendees?.firstWhere(
        (at) =>
            at?.name == organiser.name &&
            at?.emailAddress == organiser.emailAddress);
    if (attendee != null) {
      attendee.isOrganiser = true;
    }
  }
  if (json['reminders'] != null) {
    reminders = json['reminders'].map<Reminder>((decodedReminder) {
      return Reminder.fromJson(decodedReminder);
    }).toList();
  }
}