From 0d9f839027f9ff7b037e922e85430003f9f3cff7 Mon Sep 17 00:00:00 2001 From: Amir Hossein Date: Wed, 21 Dec 2022 11:05:09 +0330 Subject: [PATCH 01/11] fix: time value being int (epoch) instead of string --- lib/src/directions.response.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index addc387..da6d587 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -1242,7 +1242,9 @@ class Time { factory Time.fromMap(Map map) => Time( text: map['text'] as String?, timeZone: map['time_zone'] as String?, - value: DateTime.tryParse(map['value'] as String), + value: map['value'] != null + ? DateTime.fromMillisecondsSinceEpoch(map['value'] * 1000) + : null, ); /// The time specified as a [String]. The time is displayed in the time From c837679d0f2776768a04ad03654f95616fc5562b Mon Sep 17 00:00:00 2001 From: Amir Hossein Date: Wed, 21 Dec 2022 11:15:54 +0330 Subject: [PATCH 02/11] fix: use 'transit_details' instead of 'transit' --- lib/src/directions.response.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index da6d587..8949a04 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -804,8 +804,8 @@ class Step { instructions: map['html_instructions'] as String?, path: (map['path'] as List?)?.mapList((_) => _getGeoCoordFromMap(_)), steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)), - transit: map['transit'] != null - ? TransitDetails.fromMap(map['transit']) + transit: map['transit_details'] != null + ? TransitDetails.fromMap(map['transit_details']) : null, travelMode: map['travel_mode'] != null ? TravelMode(map['travel_mode']) : null, From 38ca548849829dcb2e730581656d7d2b77f94f91 Mon Sep 17 00:00:00 2001 From: Amir Hossein Date: Wed, 21 Dec 2022 11:27:01 +0330 Subject: [PATCH 03/11] fix: use 'local_icon' instead of 'localIcon' --- lib/src/directions.response.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index 8949a04..cfe486f 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -1367,7 +1367,7 @@ class Vehicle { name: map['name'] as String?, type: map['type'] != null ? VehicleType(map['type']) : null, icon: map['icon'] as String?, - localIcon: map['localIcon'] as String?, + localIcon: map['local_icon'] as String?, ); /// Contains the name of the vehicle on this line. eg. "Subway." From 2261bf6039e402d019798632cdce801ad79b00f1 Mon Sep 17 00:00:00 2001 From: Amir Hossein Date: Wed, 21 Dec 2022 11:30:40 +0330 Subject: [PATCH 04/11] feat: add 'LONG_DISTANCE_TRAIN' to VehicleType --- lib/src/directions.response.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index cfe486f..2941013 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -1516,6 +1516,9 @@ class VehicleType { /// Intercity bus. static const intercityBus = VehicleType('INTERCITY_BUS'); + /// Long distance train. + static const intercityBus = VehicleType('LONG_DISTANCE_TRAIN'); + /// Light rail. static const metroRail = VehicleType('METRO_RAIL'); From 52014fdc389090dd050dcac8c3ccb75e6b3a12a4 Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Wed, 21 Dec 2022 12:26:07 +0330 Subject: [PATCH 05/11] feat: add maneuver to step in response --- lib/src/directions.response.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index 2941013..6e69eda 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -791,6 +791,7 @@ class Step { this.transit, this.travelMode, this.polyline, + this.maneuver, }); factory Step.fromMap(Map map) => Step( @@ -812,6 +813,7 @@ class Step { polyline: map['polyline'] != null ? OverviewPolyline.fromMap(map['polyline']) : null, + maneuver: map['maneuver'] as String?, ); /// Contains the distance covered by this step until the next @@ -857,6 +859,10 @@ class Step { /// Contains a points describing the course of this step. final OverviewPolyline? polyline; + + /// Contains the action to take for the current step (turn left, merge, + /// straight, etc.). + final String? maneuver; } /// Transit directions return additional information that is not From 9df8ade501810801dd076be026a9ac0f967eec3e Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Wed, 21 Dec 2022 12:26:59 +0330 Subject: [PATCH 06/11] fix: wrong variable name for longDistanceTrain --- lib/src/directions.response.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index 6e69eda..e96e079 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -1523,7 +1523,7 @@ class VehicleType { static const intercityBus = VehicleType('INTERCITY_BUS'); /// Long distance train. - static const intercityBus = VehicleType('LONG_DISTANCE_TRAIN'); + static const longDistanceTrain = VehicleType('LONG_DISTANCE_TRAIN'); /// Light rail. static const metroRail = VehicleType('METRO_RAIL'); From e04d2b6a37bdff826609caaa0be2e785a6e09d75 Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Wed, 21 Dec 2022 12:39:12 +0330 Subject: [PATCH 07/11] feat: add ViaWaypoint for DirectionsLeg --- lib/src/directions.response.dart | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index e96e079..b0885ce 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -602,6 +602,7 @@ class Leg { this.startAddress, this.startLocation, this.steps, + this.viaWaypoint, }); factory Leg.fromMap(Map map) => Leg( @@ -624,6 +625,9 @@ class Leg { startAddress: map['start_address'] as String?, startLocation: _getGeoCoordFromMap(map['start_location']), steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)), + viaWaypoint: map['via_waypoint'] != null + ? ViaWaypoint.fromMap(map['via_waypoint']) + : null, ); /// Contains the estimated time of arrival for this leg. This property @@ -715,6 +719,10 @@ class Leg { /// contains an array of steps denoting information about each /// separate step of the leg of the journey. final List? steps; + + /// The locations of via waypoints along this leg. + /// contains info about points through which the route was laid + final ViaWaypoint? viaWaypoint; } /// Each element in the steps array defines a single step of the @@ -1390,6 +1398,32 @@ class Vehicle { final String? localIcon; } +/// The locations of via waypoints along this leg. +/// contains info about points through which the route was laid +class ViaWaypoint { + const ViaWaypoint({ + this.location, + this.stepIndex, + this.stepInterpolation, + }); + + factory ViaWaypoint.fromMap(Map map) => ViaWaypoint( + location: _getGeoCoordFromMap(map['location']), + stepIndex: map['step_index'] as int?, + stepInterpolation: map['step_interpolation'] as num?, + ); + + /// The location of the waypoint. + final GeoCoord? location; + + /// The index of the step containing the waypoint. + final int? stepIndex; + + /// The position of the waypoint along the step's polyline, + /// expressed as a ratio from 0 to 1. + final num? stepInterpolation; +} + /// The status field within the Directions response object contains /// the status of the request, and may contain debugging information /// to help you track down why the Directions service failed. From c30bdbe25ec84f05617dfc2f4c36126b3c9772ae Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Wed, 21 Dec 2022 12:43:55 +0330 Subject: [PATCH 08/11] fix: add longDistanceTrain to list of values --- lib/src/directions.response.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index b0885ce..e926ebf 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -1518,6 +1518,7 @@ class VehicleType { heavyRail, highSpeedTrain, intercityBus, + longDistanceTrain, metroRail, monorail, other, From 634c04fe7022f25d35aa4622d68a54a5b753aeef Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Wed, 21 Dec 2022 12:47:10 +0330 Subject: [PATCH 09/11] fix: change viaWaypoint variable to list of ViaWaypoint --- lib/src/directions.response.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/src/directions.response.dart b/lib/src/directions.response.dart index e926ebf..22aa623 100644 --- a/lib/src/directions.response.dart +++ b/lib/src/directions.response.dart @@ -625,9 +625,8 @@ class Leg { startAddress: map['start_address'] as String?, startLocation: _getGeoCoordFromMap(map['start_location']), steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)), - viaWaypoint: map['via_waypoint'] != null - ? ViaWaypoint.fromMap(map['via_waypoint']) - : null, + viaWaypoint: (map['via_waypoint'] as List?) + ?.mapList((_) => ViaWaypoint.fromMap(_)), ); /// Contains the estimated time of arrival for this leg. This property @@ -722,7 +721,7 @@ class Leg { /// The locations of via waypoints along this leg. /// contains info about points through which the route was laid - final ViaWaypoint? viaWaypoint; + final List? viaWaypoint; } /// Each element in the steps array defines a single step of the From 03a0b747cf42c7d0b11e043e07201ec7ced25a08 Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Tue, 10 Jan 2023 14:15:26 +0330 Subject: [PATCH 10/11] fix: throws exception when some optional parameters are null --- lib/src/directions.request.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/directions.request.dart b/lib/src/directions.request.dart index 24fa89b..9da5a0d 100644 --- a/lib/src/directions.request.dart +++ b/lib/src/directions.request.dart @@ -429,9 +429,9 @@ class TransitOptions { @override String toString() => - '${_addIfNotNull('arrival_time', arrivalTime!.millisecondsSinceEpoch)}' - '${_addIfNotNull('departure_time', departureTime!.millisecondsSinceEpoch)}' - '${_addIfNotNull('transit_mode', modes!.map((_) => _.toString()).join('|'))}' + '${_addIfNotNull('arrival_time', arrivalTime?.millisecondsSinceEpoch)}' + '${_addIfNotNull('departure_time', departureTime?.millisecondsSinceEpoch)}' + '${_addIfNotNull('transit_mode', modes?.map((_) => _.toString()).join('|'))}' '${_addIfNotNull('transit_routing_preference', routingPreference)}'; } @@ -556,7 +556,7 @@ class DrivingOptions { @override String toString() => - '${_addIfNotNull('departure_time', departureTime!.millisecondsSinceEpoch)}' + '${_addIfNotNull('departure_time', departureTime?.millisecondsSinceEpoch)}' '${_addIfNotNull('traffic_model', trafficModel)}'; } From db114ff2882846cfcd33060856f63e8f1b636204 Mon Sep 17 00:00:00 2001 From: SamadiPour Date: Tue, 10 Jan 2023 16:17:10 +0330 Subject: [PATCH 11/11] fix: casing of names --- lib/src/directions.dart | 8 ++++---- lib/src/directions.request.dart | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/directions.dart b/lib/src/directions.dart index 9e7ca6b..50a736d 100644 --- a/lib/src/directions.dart +++ b/lib/src/directions.dart @@ -161,16 +161,16 @@ class TravelMode { static final values = [bicycling, driving, transit, walking]; /// Specifies a bicycling directions request. - static const bicycling = TravelMode('bicycling'); + static const bicycling = TravelMode('BICYCLING'); /// Specifies a driving directions request. - static const driving = TravelMode('driving'); + static const driving = TravelMode('DRIVING'); /// Specifies a transit directions request. - static const transit = TravelMode('transit'); + static const transit = TravelMode('TRANSIT'); /// Specifies a walking directions request. - static const walking = TravelMode('walking'); + static const walking = TravelMode('WALKING'); @override int get hashCode => _name.hashCode; diff --git a/lib/src/directions.request.dart b/lib/src/directions.request.dart index 9da5a0d..159179b 100644 --- a/lib/src/directions.request.dart +++ b/lib/src/directions.request.dart @@ -221,7 +221,7 @@ class DirectionsRequest { @override String toString() => '?origin=${_convertLocation(origin)}&' 'destination=${_convertLocation(destination)}' - '${_addIfNotNull('mode', travelMode)}' + '${_addIfNotNull('mode', travelMode?.toString().toLowerCase())}' '${_addIfNotNull('waypoints', _convertWaypoints())}' '${_addIfNotNull('alternatives', alternatives)}' '${_addIfNotNull('avoid', _convertAvoids())}' @@ -628,23 +628,23 @@ class TransitMode { /// Indicates that the calculated route should prefer travel /// by bus. - static const bus = TransitMode('BUS'); + static const bus = TransitMode('bus'); /// Indicates that the calculated route should prefer travel /// by bus. - static const subway = TransitMode('SUBWAY'); + static const subway = TransitMode('subway'); /// Indicates that the calculated route should prefer travel /// by bus. - static const train = TransitMode('TRAIN'); + static const train = TransitMode('train'); /// Indicates that the calculated route should prefer travel /// by bus. - static const tram = TransitMode('TRAM'); + static const tram = TransitMode('tram'); /// Indicates that the calculated route should prefer travel /// by bus. - static const rail = TransitMode('RAIL'); + static const rail = TransitMode('rail'); @override String toString() => _name;