decodeTripDetails static method
Implementation
static TripDetails? decodeTripDetails(Object? mapInput){
if(mapInput == null || !(mapInput is Map?)){
return null;
}
try {
Map map = mapInput as Map;
String? id = map['id'];
String? name = map['name'];
String? description = map['description'];
String? tripState = map['trip_state'];
var totalDistance = map['total_distance'];
var totalDuration = map['total_duration'];
var totalElevationGain = map['total_elevation_gain'];
var metadata = map['metadata'];
StartLocation? startLocation = JsonDecoder.decodeStartLocation(
map['start_location']);
EndLocation? endLocation = JsonDecoder.decodeEndLocation(
map['end_location']);
User? user = JsonDecoder.decodeUser(map['user']);
String? startedAt = map['started_at'];
String? endedAt = map['ended_at'];
String? createdAt = map['created_at'];
String? updatedAt = map['updated_at'];
bool? isLocal = map['is_local'];
bool? hasMore = map['has_more'];
List? stopsMapList = map['stops'];
List<Stop?> stops = List.empty(growable: true);
stopsMapList?.forEach((stopMap) {
Stop? stop = JsonDecoder.decodeStop(stopMap);
stops.add(stop);
});
List? eventsMapList = map['events'];
List<Events?> eventsList = List.empty(growable: true);
eventsMapList?.forEach((eventsMap) {
Events? events = JsonDecoder.decodeEvents(eventsMap);
eventsList.add(events);
});
List? routeMapList = map['route'];
List<Routes?> routesList = List.empty(growable: true);
routeMapList?.forEach((routesMap) {
Routes? routes = JsonDecoder.decodeRoutes(routesMap);
routesList.add(routes);
});
Map? routeIndex = map['routeIndex'];
TripDetails tripDetails = TripDetails(
id: id,
name: name,
description: description,
tripState: tripState,
totalDistance: totalDistance,
totalDuration: totalDuration,
totalElevationGain: totalElevationGain,
metadata: metadata,
startLocation: startLocation,
endLocation: endLocation,
user: user,
startedAt: startedAt,
endedAt: endedAt,
createdAt: createdAt,
updatedAt: updatedAt,
isLocal: isLocal,
hasMore: hasMore,
stops: stops,
events: eventsList,
route: routesList,
routeIndex: routeIndex
);
return tripDetails;
} catch(error){
print('decodeTripDetail: ' + error.toString());
return null;
}
}