parseRoad function

Future<Road> parseRoad(
  1. ParserRoadComputeArg data
)

parseRoad this method used to parse json get it from route service to Road object we use this method in another thread like compute the data is ParserRoadComputeArg that will to be parsed to Road fix parsing problem #1 return Road object that contain list of waypoint and distance and duration of the road

Implementation

Future<Road> parseRoad(ParserRoadComputeArg data) async {
  Map<String, dynamic> jsonResponse = data.jsonRoad;
  bool alternative = data.alternative;
  var road = Road.empty();
  final List<Map<String, dynamic>> routes =
      List.castFrom(jsonResponse["routes"]);

  final route = routes.first;

  road = Road.fromOSRMJson(
    route: route,
  );

  if (routes.length > 1 && alternative) {
    routes.removeAt(0);
    for (var route in routes) {
      final alternative = Road.fromOSRMJson(
        route: route,
      );
      road.addAlternativeRoute(alternative);
    }
  }

  return road;
}