BusPosition.fromJson constructor

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

Creates a BusPosition object from a JSON object.

Implementation

factory BusPosition.fromJson(Map<String, dynamic> json) {
  return BusPosition(
    dateTime:
        DateTime.tryParse(json[ApiFields.dateTime] ?? '') ?? emptyDateTime,
    deviationMinutes:
        ((json[ApiFields.deviationMinutes] ?? -9999) as num).toInt(),
    direction: json[ApiFields.direction] ?? '',
    latitude: ((json[ApiFields.latitude] ?? 0.0) as num).toDouble(),
    longitude: ((json[ApiFields.longitude] ?? 0.0) as num).toDouble(),
    routeId: json[ApiFields.routeId] ?? '',
    tripStartTime: DateTime.tryParse(json[ApiFields.tripStartTime] ?? '') ??
        emptyDateTime,
    tripEndTime:
        DateTime.tryParse(json[ApiFields.tripEndTime] ?? '') ?? emptyDateTime,
    tripHeadsign: json[ApiFields.tripHeadsign] ?? '',
    tripId: json[ApiFields.tripId] ?? '',
    vehicleId: json[ApiFields.vehicleId] ?? '',
  );
}