ScheduleDirection.fromJson constructor

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

Creates a ScheduleDirection object from a JSON object.

Implementation

factory ScheduleDirection.fromJson(Map<String, dynamic> json) {
  return ScheduleDirection(
    endTime:
        DateTime.tryParse(json[ApiFields.endTime] ?? '') ?? emptyDateTime,
    routeId: json[ApiFields.routeId] ?? '',
    startTime:
        DateTime.tryParse(json[ApiFields.startTime] ?? '') ?? emptyDateTime,
    stops: ((json[ApiFields.stopTimes] as List?) ?? [])
        .map((scheduleStop) => ScheduleStop.fromJson(scheduleStop))
        .toList(),
    direction: json[ApiFields.tripDirection] ?? '',
    tripHeadsign: json[ApiFields.tripHeadsign] ?? '',
    tripId: json[ApiFields.tripId] ?? '',
  );
}