Dhi13man / open_route_service

An encapsulation made around openrouteservice API for Dart and Flutter projects. Made for easy generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation and routing Optimizations using their amazing API.
https://pub.dev/packages/open_route_service
MIT License
30 stars 7 forks source link

Error when running matrixPost with metrics: ['distance'] #12

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hello. I'm getting the following error when doing a matrixPost with metrics different from the default ['duration'] TimeDistanceMatrix distanceMatrix = await client.matrixPost(locations: cities, metrics: ['distance'], units: 'm'); Do you have any idea why this happens? The request works OK in Postman, why is this happening in Flutter Dart? How can I fix it?

Error: OpenRouteServiceException: Expected a value of type 'List<dynamic>', but got one of type 'Null'; Matrix value can't be determined for given inputs, as per https://openrouteservice.org/dev/#/api-docs/v2/matrix/{profile}/post, at url https://api.openrouteservice.org/v2/matrix/driving-car at Object.throw_ [as throw] (http://localhost:3277/dart_sdk.js:5080:11) at ORSMatrix$124matrixPost (http://localhost:3277/packages/open_route_service/src/open_route_service_base.dart.lib.js:1087:21) at ORSMatrix$124matrixPost.next (<anonymous>) at http://localhost:3277/dart_sdk.js:40641:33 at _RootZone.runUnary (http://localhost:3277/dart_sdk.js:40511:59) at _FutureListener.thenAwait.handleValue (http://localhost:3277/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:3277/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:3277/dart_sdk.js:36037:17) at [_completeWithValue] (http://localhost:3277/dart_sdk.js:35872:23) at async._AsyncCallbackEntry.new.callback (http://localhost:3277/dart_sdk.js:35906:35) at Object._microtaskLoop (http://localhost:3277/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:3277/dart_sdk.js:40784:13) at http://localhost:3277/dart_sdk.js:36261:9

Dhi13man commented 2 years ago

Hello. I'm getting the following error when doing a matrixPost with metrics different from the default ['duration'] TimeDistanceMatrix distanceMatrix = await client.matrixPost(locations: cities, metrics: ['distance'], units: 'm'); Do you have any idea why this happens? The request works OK in Postman, why is this happening in Flutter Dart? How can I fix it?

Error: OpenRouteServiceException: Expected a value of type 'List<dynamic>', but got one of type 'Null'; Matrix value can't be determined for given inputs, as per https://openrouteservice.org/dev/#/api-docs/v2/matrix/{profile}/post, at url https://api.openrouteservice.org/v2/matrix/driving-car at Object.throw_ [as throw] (http://localhost:3277/dart_sdk.js:5080:11) at ORSMatrix$124matrixPost (http://localhost:3277/packages/open_route_service/src/open_route_service_base.dart.lib.js:1087:21) at ORSMatrix$124matrixPost.next (<anonymous>) at http://localhost:3277/dart_sdk.js:40641:33 at _RootZone.runUnary (http://localhost:3277/dart_sdk.js:40511:59) at _FutureListener.thenAwait.handleValue (http://localhost:3277/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:3277/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:3277/dart_sdk.js:36037:17) at [_completeWithValue] (http://localhost:3277/dart_sdk.js:35872:23) at async._AsyncCallbackEntry.new.callback (http://localhost:3277/dart_sdk.js:35906:35) at Object._microtaskLoop (http://localhost:3277/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:3277/dart_sdk.js:40784:13) at http://localhost:3277/dart_sdk.js:36261:9

Hmmm just seems like a issue of making the list nullable. Will diagnose this in a few hours.

ghost commented 2 years ago

@Dhi13man I tried finding out what's wrong but I keep getting the same error. It doesn't make sense, the list of locations I pass isn't null, it's in correct type and everything. Tried everything. metris ['distance'] causes the problem but can't find out why. I run it again and this time the same error is thrown at a different line:

Error: OpenRouteServiceException: Expected a value of type 'List', but got one of type 'Null'; Matrix value can't be determined for given inputs, as per https://openrouteservice.org/dev/#/api-docs/v2/matrix/{profile}/post, at url https://api.openrouteservice.org/v2/matrix/driving-car at Object.throw_ [as throw] (http://localhost:3277/dart_sdk.js:5080:11) at ORSMatrix$124matrixPost (http://localhost:3277/packages/open_route_service/src/open_route_service_base.dart.lib.js:1087:21) at ORSMatrix$124matrixPost.next () at http://localhost:3277/dart_sdk.js:40641:33 at _RootZone.runUnary (http://localhost:3277/dart_sdk.js:40511:59) at _FutureListener.thenAwait.handleValue (http://localhost:3277/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:3277/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:3277/dart_sdk.js:36037:17) at [_completeWithValue] (http://localhost:3277/dart_sdk.js:35872:23) at async._AsyncCallbackEntry.new.callback (http://localhost:3277/dart_sdk.js:35906:35) at Object._microtaskLoop (http://localhost:3277/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:3277/dart_sdk.js:40784:13) at http://localhost:3277/dart_sdk.js:36261:9

Please let me know if there is anything I could do to help you troubleshoot it, I need it fixed for my project. Thanks.

Dhi13man commented 2 years ago

Checking now.

Dhi13man commented 2 years ago

Please fork and test the branch 12-error-when-running-matrixpost-with-metrics-distance. The Issue should be resolved there. If everything works fine, will deploy new version with fix.

ghost commented 2 years ago

Please fork and test the branch 12-error-when-running-matrixpost-with-metrics-distance. The Issue should be resolved there. If everything works fine, will deploy new version with fix.

Yes, it works!!! No error and I get the response I wanted. Everything seems okay. Thank you so much for the quick fix!

Dhi13man commented 2 years ago

Package v1.2.2 with the fix is now up on pub.dev. Thank you for your cooperation.