diff --git a/example/directions.dart b/example/directions.dart index 3d4b08c..9fd0917 100644 --- a/example/directions.dart +++ b/example/directions.dart @@ -6,7 +6,8 @@ import 'package:google_maps_webservice/directions.dart'; final directions = new GoogleMapsDirections(Platform.environment["API_KEY"]); main() async { - DirectionsResponse res = await directions.directionsWithAddress("Paris, France", "Rennes, France"); + DirectionsResponse res = + await directions.directionsWithAddress("Paris, France", "Rennes, France"); print(res.status); if (res.isOkay) { diff --git a/lib/src/directions.dart b/lib/src/directions.dart index e3f71f0..c145619 100644 --- a/lib/src/directions.dart +++ b/lib/src/directions.dart @@ -15,17 +15,17 @@ class GoogleMapsDirections extends GoogleWebService { Future directions(origin, destination, {TravelMode travelMode, - List waypoints, - bool alternatives, - RouteType avoid, - String language, - Unit units, - String region, - arrivalTime, - departureTime, - List transitMode, - TrafficModel trafficModel, - TransitRoutingPreferences transitRoutingPreference}) async { + List waypoints, + bool alternatives, + RouteType avoid, + String language, + Unit units, + String region, + arrivalTime, + departureTime, + List transitMode, + TrafficModel trafficModel, + TransitRoutingPreferences transitRoutingPreference}) async { final url = buildUrl( origin: origin, destination: destination, @@ -43,20 +43,20 @@ class GoogleMapsDirections extends GoogleWebService { return _decode(await doGet(url)); } - Future directionsWithLocation(Location origin, - Location destination, + Future directionsWithLocation( + Location origin, Location destination, {TravelMode travelMode, - List waypoints, - bool alternatives, - RouteType avoid, - String language, - Unit units, - String region, - arrivalTime, - departureTime, - List transitMode, - TrafficModel trafficModel, - TransitRoutingPreferences transitRoutingPreference}) async { + List waypoints, + bool alternatives, + RouteType avoid, + String language, + Unit units, + String region, + arrivalTime, + departureTime, + List transitMode, + TrafficModel trafficModel, + TransitRoutingPreferences transitRoutingPreference}) async { return directions(origin, destination, travelMode: travelMode, waypoints: waypoints, @@ -71,20 +71,20 @@ class GoogleMapsDirections extends GoogleWebService { transitRoutingPreference: transitRoutingPreference); } - Future directionsWithAddress(String origin, - String destination, + Future directionsWithAddress( + String origin, String destination, {TravelMode travelMode, - List waypoints, - bool alternatives, - RouteType avoid, - String language, - Unit units, - String region, - arrivalTime, - departureTime, - List transitMode, - TrafficModel trafficModel, - TransitRoutingPreferences transitRoutingPreference}) async { + List waypoints, + bool alternatives, + RouteType avoid, + String language, + Unit units, + String region, + arrivalTime, + departureTime, + List transitMode, + TrafficModel trafficModel, + TransitRoutingPreferences transitRoutingPreference}) async { return directions(origin, destination, travelMode: travelMode, waypoints: waypoints, @@ -99,20 +99,21 @@ class GoogleMapsDirections extends GoogleWebService { transitRoutingPreference: transitRoutingPreference); } - String buildUrl({origin, - destination, - TravelMode travelMode, - List waypoints, - bool alternatives, - RouteType avoid, - String language, - Unit units, - String region, - arrivalTime, - departureTime, - List transitMode, - TrafficModel trafficModel, - TransitRoutingPreferences transitRoutingPreference}) { + String buildUrl( + {origin, + destination, + TravelMode travelMode, + List waypoints, + bool alternatives, + RouteType avoid, + String language, + Unit units, + String region, + arrivalTime, + departureTime, + List transitMode, + TrafficModel trafficModel, + TransitRoutingPreferences transitRoutingPreference}) { if (origin is! Location && origin is! String) { throw new ArgumentError("'origin' must be a '$String' or a '$Location'"); } @@ -155,9 +156,9 @@ class GoogleMapsDirections extends GoogleWebService { : departureTime, "traffic_model": trafficModelToString(trafficModel), "transit_mode": - transitMode?.map((t) => transitModeToString(t))?.join("|"), + transitMode?.map((t) => transitModeToString(t))?.join("|"), "transit_routing_preference": - transitRoutingPreferencesToString(transitRoutingPreference) + transitRoutingPreferencesToString(transitRoutingPreference) }; return "$url?${buildQuery(params)}"; @@ -173,20 +174,19 @@ class DirectionsResponse extends GoogleResponseStatus { final List routes; - DirectionsResponse(String status, String errorMessage, this.geocodedWaypoints, - this.routes) + DirectionsResponse( + String status, String errorMessage, this.geocodedWaypoints, this.routes) : super(status, errorMessage); - factory DirectionsResponse.fromJson(Map json) => - new DirectionsResponse( - json["status"], - json["error_message"], - json["geocoded_waypoints"]?.map((r) { - return new GeocodedWaypoint.fromJson(r); - })?.toList() as List, - json["routes"]?.map((r) { - return new Route.fromJson(r); - })?.toList() as List); + factory DirectionsResponse.fromJson(Map json) => new DirectionsResponse( + json["status"], + json["error_message"], + json["geocoded_waypoints"]?.map((r) { + return new GeocodedWaypoint.fromJson(r); + })?.toList() as List, + json["routes"]?.map((r) { + return new Route.fromJson(r); + })?.toList() as List); } class Waypoint { @@ -220,15 +220,14 @@ class GeocodedWaypoint { /// JSON partial_match final String partialMatch; - GeocodedWaypoint(this.geocoderStatus, this.placeId, this.types, - this.partialMatch); + GeocodedWaypoint( + this.geocoderStatus, this.placeId, this.types, this.partialMatch); - factory GeocodedWaypoint.fromJson(Map json) => - new GeocodedWaypoint( - json["geocoder_status"], - json["place_id"], - json["types"] as List, - json["partial_match"]); + factory GeocodedWaypoint.fromJson(Map json) => new GeocodedWaypoint( + json["geocoder_status"], + json["place_id"], + json["types"] as List, + json["partial_match"]); } class Route { @@ -251,9 +250,8 @@ class Route { Route(this.summary, this.legs, this.copyrights, this.overviewPolyline, this.warnings, this.waypointOrder, this.bounds, this.fare); - factory Route.fromJson(Map json) => - json != null - ? new Route( + factory Route.fromJson(Map json) => json != null + ? new Route( json["summary"], json["legs"]?.map((r) { return new Leg.fromJson(r); @@ -264,7 +262,7 @@ class Route { json["waypoint_order"] as List, new Bounds.fromJson(json["bounds"]), new Fare.fromJson(json["fare"])) - : null; + : null; } abstract class _Step { @@ -299,7 +297,8 @@ class Leg extends _Step { /// JSON departure_time final Time departureTime; - Leg(this.steps, + Leg( + this.steps, this.startAddress, this.endAddress, this.durationInTraffic, @@ -311,9 +310,8 @@ class Leg extends _Step { Value distance) : super(startLocation, endLocation, duration, distance); - factory Leg.fromJson(Map json) => - json != null - ? new Leg( + factory Leg.fromJson(Map json) => json != null + ? new Leg( json["steps"]?.map((r) { return new Step.fromJson(r); })?.toList() as List, @@ -326,7 +324,7 @@ class Leg extends _Step { new Location.fromJson(json["end_location"]), new Value.fromJson(json["duration"]), new Value.fromJson(json["distance"])) - : null; + : null; } class Step extends _Step { @@ -341,7 +339,8 @@ class Step extends _Step { /// JSON transit_details final TransitDetails transitDetails; - Step(this.travelMode, + Step( + this.travelMode, this.htmlInstructions, this.polyline, this.transitDetails, @@ -351,9 +350,8 @@ class Step extends _Step { Value distance) : super(startLocation, endLocation, duration, distance); - factory Step.fromJson(Map json) => - json != null - ? new Step( + factory Step.fromJson(Map json) => json != null + ? new Step( stringToTravelMode(json["travel_mode"]), json["html_instructions"], new Polyline.fromJson(json["polyline"]), @@ -362,7 +360,7 @@ class Step extends _Step { new Location.fromJson(json["end_location"]), new Value.fromJson(json["duration"]), new Value.fromJson(json["distance"])) - : null; + : null; } enum TravelMode { driving, walking, bicycling, transit } @@ -492,10 +490,9 @@ class Fare extends Value { Fare(this.currency, num value, String text) : super(value, text); - factory Fare.fromJson(Map json) => - json != null - ? new Fare(json["currency"], json["value"], json["text"]) - : null; + factory Fare.fromJson(Map json) => json != null + ? new Fare(json["currency"], json["value"], json["text"]) + : null; } class Time extends Value { @@ -504,10 +501,9 @@ class Time extends Value { Time(this.timeZone, num value, String text) : super(value, text); - factory Time.fromJson(Map json) => - json != null - ? new Time(json["time_zone"], json["value"], json["text"]) - : null; + factory Time.fromJson(Map json) => json != null + ? new Time(json["time_zone"], json["value"], json["text"]) + : null; } class TransitDetails { @@ -533,18 +529,16 @@ class TransitDetails { TransitDetails(this.arrivalStop, this.departureStop, this.arrivalTime, this.departureTime, this.headsign, this.headway, this.numStops); - factory TransitDetails.fromJson(Map json) => - json != null - ? new TransitDetails( + factory TransitDetails.fromJson(Map json) => json != null + ? new TransitDetails( new Stop.fromJson(json["arrival_stop"]), new Stop.fromJson(json["departure_stop"]), new Time.fromJson(json["arrival_time"]), new Time.fromJson(json["departure_time"]), json["headsign"], json["headway"], - json["num_stops"] - ) - : null; + json["num_stops"]) + : null; } class Stop { @@ -553,10 +547,9 @@ class Stop { Stop(this.name, this.location); - factory Stop.fromJson(Map json) => - json != null - ? new Stop(json["name"], new Location.fromJson(json["location"])) - : null; + factory Stop.fromJson(Map json) => json != null + ? new Stop(json["name"], new Location.fromJson(json["location"])) + : null; } class Line { @@ -581,9 +574,8 @@ class Line { Line(this.name, this.shortName, this.color, this.agencies, this.url, this.icon, this.textColor, this.vehicle); - factory Line.fromJson(Map json) => - json != null - ? new Line( + factory Line.fromJson(Map json) => json != null + ? new Line( json["name"], json["short_name"], json["color"], @@ -592,8 +584,7 @@ class Line { json["icon"], json["text_color"], new VehicleType.fromJson(json["vehicle"])) - : null; - + : null; } class TransitAgency { @@ -603,10 +594,9 @@ class TransitAgency { TransitAgency(this.name, this.url, this.phone); - factory TransitAgency.fromJson(Map json) => - json != null - ? new TransitAgency(json["name"], json["url"], json["phone"]) - : null; + factory TransitAgency.fromJson(Map json) => json != null + ? new TransitAgency(json["name"], json["url"], json["phone"]) + : null; } class VehicleType { @@ -619,9 +609,10 @@ class VehicleType { VehicleType(this.name, this.type, this.icon, this.localIcon); - factory VehicleType.fromJson(Map json) => - json != null ? new VehicleType( - json["name"], json["type"], json["icon"], json["local_icon"]) : null; + factory VehicleType.fromJson(Map json) => json != null + ? new VehicleType( + json["name"], json["type"], json["icon"], json["local_icon"]) + : null; bool isType(String type) => type.toLowerCase() == this.type.toLowerCase(); @@ -642,4 +633,4 @@ class VehicleType { static const gondolaLift = "GONDOLA_LIFT"; static const funicular = "FUNICULAR"; static const other = "OTHER"; -} \ No newline at end of file +} diff --git a/test/directions_test.dart b/test/directions_test.dart index c4baa7a..4b40a83 100644 --- a/test/directions_test.dart +++ b/test/directions_test.dart @@ -18,32 +18,37 @@ launch([Client client]) async { group("Google Maps Directions", () { group("build url", () { test("simple with String origin/destination", () { - expect(directions.buildUrl( - origin: "Paris, France", destination: "Marseilles, France"), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=${Uri + expect( + directions.buildUrl( + origin: "Paris, France", destination: "Marseilles, France"), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=${Uri .encodeComponent("Paris, France")}&destination=${Uri .encodeComponent("Marseilles, France")}")); }); test("simple with Location origin/destination", () { - expect(directions.buildUrl( - origin: new Location(23.43, 65.1), - destination: new Location(62.323, 53.1)), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=23.43,65.1&destination=62.323,53.1")); + expect( + directions.buildUrl( + origin: new Location(23.43, 65.1), + destination: new Location(62.323, 53.1)), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=23.43,65.1&destination=62.323,53.1")); }); test("simple with String/Location origin/destination", () { - expect(directions.buildUrl( - origin: new Location(23.43, 65.1), - destination: "Marseilles, France"), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=23.43,65.1&destination=${Uri + expect( + directions.buildUrl( + origin: new Location(23.43, 65.1), + destination: "Marseilles, France"), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=23.43,65.1&destination=${Uri .encodeComponent("Marseilles, France")}")); }); test("simple with bad type for origin/destination", () { try { - directions.buildUrl( - origin: 10, destination: "Marseilles, France"); + directions.buildUrl(origin: 10, destination: "Marseilles, France"); } catch (e) { expect((e as ArgumentError).message, equals("'origin' must be a '$String' or a '$Location'")); @@ -59,142 +64,198 @@ launch([Client client]) async { }); test("avoid", () { - expect(directions.buildUrl( - origin: "Toronto", destination: "Montreal", avoid: RouteType.tolls), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + avoid: RouteType.tolls), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=tolls")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - avoid: RouteType.highways), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=highways")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - avoid: RouteType.indoor), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=indoor")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - avoid: RouteType.ferries), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=ferries")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + avoid: RouteType.highways), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=highways")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + avoid: RouteType.indoor), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=indoor")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + avoid: RouteType.ferries), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&avoid=ferries")); }); test("travel_mode", () { - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - travelMode: TravelMode.bicycling), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=bicycling")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - travelMode: TravelMode.driving), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=driving")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - travelMode: TravelMode.transit), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=transit")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - travelMode: TravelMode.walking), equals( - "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=walking")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + travelMode: TravelMode.bicycling), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=bicycling")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + travelMode: TravelMode.driving), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=driving")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + travelMode: TravelMode.transit), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=transit")); + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + travelMode: TravelMode.walking), + equals( + "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&mode=walking")); }); test("departure_time", () { int d = 1343641500; - expect(directions.buildUrl( - origin: "Toronto", destination: "Montreal", departureTime: d), + expect( + directions.buildUrl( + origin: "Toronto", destination: "Montreal", departureTime: d), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&departure_time=$d")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - departureTime: new DateTime.fromMillisecondsSinceEpoch(d * 1000)), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + departureTime: + new DateTime.fromMillisecondsSinceEpoch(d * 1000)), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&departure_time=$d")); }); test("arrival_time", () { int d = 1343641500; - expect(directions.buildUrl( - origin: "Toronto", destination: "Montreal", arrivalTime: d), + expect( + directions.buildUrl( + origin: "Toronto", destination: "Montreal", arrivalTime: d), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&arrival_time=$d")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - arrivalTime: new DateTime.fromMillisecondsSinceEpoch(d * 1000)), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + arrivalTime: new DateTime.fromMillisecondsSinceEpoch(d * 1000)), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&arrival_time=$d")); }); test("units", () { - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - units: Unit.metric), + expect( + directions.buildUrl( + origin: "Toronto", destination: "Montreal", units: Unit.metric), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&units=metric")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - units: Unit.imperial), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + units: Unit.imperial), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&units=imperial")); }); test("traffic_model", () { - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - trafficModel: TrafficModel.bestGuess), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + trafficModel: TrafficModel.bestGuess), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&traffic_model=best_guess")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - trafficModel: TrafficModel.pessimistic), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + trafficModel: TrafficModel.pessimistic), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&traffic_model=pessimistic")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - trafficModel: TrafficModel.optimistic), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + trafficModel: TrafficModel.optimistic), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&traffic_model=optimistic")); }); test("transit_mode", () { - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - transitMode: [TransitMode.rail]), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + transitMode: [TransitMode.rail]), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&transit_mode=rail")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - transitMode: [TransitMode.bus]), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + transitMode: [TransitMode.bus]), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&transit_mode=bus")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - transitMode: [ - TransitMode.tram, TransitMode.train, TransitMode.subway]), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + transitMode: [ + TransitMode.tram, + TransitMode.train, + TransitMode.subway + ]), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&transit_mode=tram|train|subway")); }); test("transit_routing_preference", () { - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - transitRoutingPreference: TransitRoutingPreferences.lessWalking), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + transitRoutingPreference: + TransitRoutingPreferences.lessWalking), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&transit_routing_preference=less_walking")); - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - transitRoutingPreference: TransitRoutingPreferences.fewerTransfers), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + transitRoutingPreference: + TransitRoutingPreferences.fewerTransfers), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&transit_routing_preference=fewer_transfers")); }); test("waypoints", () { - expect(directions.buildUrl(origin: "Toronto", - destination: "Montreal", - waypoints: [ - Waypoint.optimize(), - Waypoint.fromAddress("Paris"), - Waypoint.fromLocation(new Location(42.2, 21.3)), - Waypoint.fromPlaceId("ChIJ3S-JXmauEmsRUcIaWtf4MzE"), - Waypoint.fromEncodedPolyline("gfo}EtohhU") - ]), + expect( + directions.buildUrl( + origin: "Toronto", + destination: "Montreal", + waypoints: [ + Waypoint.optimize(), + Waypoint.fromAddress("Paris"), + Waypoint.fromLocation(new Location(42.2, 21.3)), + Waypoint.fromPlaceId("ChIJ3S-JXmauEmsRUcIaWtf4MzE"), + Waypoint.fromEncodedPolyline("gfo}EtohhU") + ]), equals( "https://maps.googleapis.com/maps/api/directions/json?key=$apiKey&origin=Toronto&destination=Montreal&waypoints=optimize:true|Paris|42.2,21.3|place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE|enc:gfo}EtohhU:")); }); @@ -202,7 +263,7 @@ launch([Client client]) async { test("decode response", () { DirectionsResponse response = - new DirectionsResponse.fromJson(JSON.decode(_responseExample)); + new DirectionsResponse.fromJson(JSON.decode(_responseExample)); expect(response.isOkay, isTrue); expect(response.routes, hasLength(equals(1))); @@ -250,101 +311,29 @@ launch([Client client]) async { equals( "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e")); - expect(response - .routes - .first - .legs - .first - .steps - .first - .polyline - .points, + expect(response.routes.first.legs.first.steps.first.polyline.points, equals("a~l~Fjk~uOwHJy@P")); - expect(response - .routes - .first - .legs - .first - .steps - .first - .duration - .text, + expect(response.routes.first.legs.first.steps.first.duration.text, equals("1 min")); - expect(response - .routes - .first - .legs - .first - .steps - .first - .duration - .value, + expect(response.routes.first.legs.first.steps.first.duration.value, equals(19)); - expect(response - .routes - .first - .legs - .first - .steps - .first - .distance - .text, + expect(response.routes.first.legs.first.steps.first.distance.text, equals("0.1 mi")); - expect(response - .routes - .first - .legs - .first - .steps - .first - .distance - .value, + expect(response.routes.first.legs.first.steps.first.distance.value, equals(207)); - expect(response - .routes - .first - .legs - .first - .steps - .first - .startLocation - .lat, + expect(response.routes.first.legs.first.steps.first.startLocation.lat, equals(41.8507300)); - expect(response - .routes - .first - .legs - .first - .steps - .first - .startLocation - .lng, + expect(response.routes.first.legs.first.steps.first.startLocation.lng, equals(-87.6512600)); - expect(response - .routes - .first - .legs - .first - .steps - .first - .endLocation - .lat, + expect(response.routes.first.legs.first.steps.first.endLocation.lat, equals(41.8525800)); - expect(response - .routes - .first - .legs - .first - .steps - .first - .endLocation - .lng, + expect(response.routes.first.legs.first.steps.first.endLocation.lng, equals(-87.6514100)); expect(response.routes.first.legs.first.steps.first.travelMode,