Event.fromJson constructor

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

Implementation

Event.fromJson(Map<String, dynamic> data) {
  startTime = data['startTime'] != null
      ? DateTime.parse(data['startTime']).toLocal()
      : null;
  endTime = data['endTime'] != null
      ? DateTime.parse(data['endTime']).toLocal()
      : null;
  isRecurring = data['isRecurring'] == 'true' ? true : false;
  if (!isRecurring!) {
    date = data['date'] != 'null' ? DateTime.parse(data['date']) : null;
    endDate =
        data['endDate'] != 'null' ? DateTime.parse(data['endDate']) : null;
  } else {
    repeatDuration = data['repeatDuration'] != 'null'
        ? int.parse(data['repeatDuration'])
        : null;
    repeatCycle = (data['repeatCycle'] == RepeatCycle.WEEK.toString()
        ? RepeatCycle.WEEK
        : (data['repeatCycle'] == RepeatCycle.MONTH.toString()
            ? RepeatCycle.MONTH
            : null));
    switch (repeatCycle) {
      case RepeatCycle.WEEK:
        occursOn = (data['occursOn'] == Week.SUNDAY.toString()
            ? Week.SUNDAY
            : (data['occursOn'] == Week.MONDAY.toString()
                ? Week.MONDAY
                : (data['occursOn'] == Week.TUESDAY.toString()
                    ? Week.TUESDAY
                    : (data['occursOn'] == Week.WEDNESDAY.toString()
                        ? Week.WEDNESDAY
                        : (data['occursOn'] == Week.THURSDAY.toString()
                            ? Week.THURSDAY
                            : (data['occursOn'] == Week.FRIDAY.toString()
                                ? Week.FRIDAY
                                : (data['occursOn'] ==
                                        Week.SATURDAY.toString()
                                    ? Week.SATURDAY
                                    : null)))))));
        break;
      case RepeatCycle.MONTH:
        date = data['date'] != 'null' ? DateTime.parse(data['date']) : null;
        break;
      default:
        null;
    }
    endsOn = (data['endsOn'] == EndsOn.NEVER.toString()
        ? EndsOn.NEVER
        : (data['endsOn'] == EndsOn.ON.toString()
            ? EndsOn.ON
            : (data['endsOn'] == EndsOn.AFTER.toString()
                ? EndsOn.AFTER
                : null)));
    switch (endsOn) {
      case EndsOn.ON:
        endEventOnDate = data['endEventOnDate'] != 'null'
            ? DateTime.parse(data['endEventOnDate'])
            : null;
        break;
      case EndsOn.AFTER:
        endEventAfterOccurance = data['endEventAfterOccurance'] != 'null'
            ? int.parse(data['endEventAfterOccurance'])
            : null;
        break;
      case EndsOn.NEVER:
        break;
      default:
        null;
    }
  }
}