Esri / arcgis-maps-sdk-flutter-samples

Sample code for ArcGIS Maps SDK for Flutter
Apache License 2.0
14 stars 5 forks source link

"Show service area" sample fails with API key #135

Closed contfedorov closed 2 months ago

contfedorov commented 2 months ago

"Show service area" sample fails when I use my API key (copied from dev dashboard). It opens page with sample, renders UI, loads basemap, and shows spinner forever. But if I use OAuth token as an API key, it works well. Note: I don't set up OAuth, I just insert my OAuth token literally to the place where API key is expected to be.

Possibly, my API key does not have appropriate privileges. Nevertheless, app should handle this correctly and don't throw an exception.

I use:

Here is the stacktrace.

Launching lib/main.dart on iPhone 15 in debug mode...
Running Xcode build...
Xcode build done.                                           24.6s
Debug service listening on ws://127.0.0.1:54124/ALpYEX3VT6I=/ws
Syncing files to device iPhone 15...
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ArcGISException: code=15; Invalid call.; Object failed to load, unable to execute task.
#0      _extension#20.result.<anonymous closure> (package:arcgis_maps/src/core_interoperability/future_conversion.dart:71:9)
#1      new Result (package:async/src/result/result.dart:65:40)
#2      _extension#20.result (package:arcgis_maps/src/core_interoperability/future_conversion.dart:65:12)
#3      _extension#19.toFuture.<anonymous closure> (package:arcgis_maps/src/core_interoperability/future_conversion.dart:35:35)
<asynchronous suspension>
#4      _ShowServiceAreaState.onMapViewReady (package:arcgis_maps_sdk_flutter_samples/samples/show_service_area/show_service_area.dart:180:30)
<asynchronous suspension>

Screenshot 2024-09-03 at 18 26 31

jenmerritt commented 2 months ago

Hi there, I wanted to run some tests to make sure I could replicate with regards to an invalid API key - and I can, so it looks like you are right regarding the cause of the exception.

There are 2 things to mention: Firstly, agree that it isn't helpful not getting information about the API key in the error message. This is something we're working to improve in our next release. Right now with Beta 2, if load is called explicitly on loadable objects, such as layers, an exception is raised relating to the API key permissions. However in some cases, including in this sample for the service area task, loading is completed implicitly (as part of another operation / without a direct call to load). In our next release we are going to provide more error information in this scenario. So we expect this experience to improve.

With regards to handling exceptions - we try to strike a balance in our sample implementations between focusing on the key story of the area of API being demonstrated - the key classes, method calls, workflows etc. - and including everything you might see in a fully functioning application. That being said, we appreciate the feedback and will continue to bear this in mind with our sample implementations.

contfedorov commented 2 months ago

@jenmerritt Thanks for looking into this!