Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception when using Geolocation with Dart

Working in Dart with Geolocation. The geoposition object passed to the callback does not always have altitude, speed or direction. My question is how I check for this to prevent an exception from being thrown?

I know I can use exception handling but would prefer to detect the situation. At least in the Dart Editor the debugger pauses execution, it seems, even if the exception is caught...

I've tried

if(solution.coords.altitude==null) { ... }
if(solution.coords.altitude is num) { ... }

These cause exceptions. In the debugger altitude does not show as an available field in the object. On a device, with the right settings, altitude is included.

How do I deal with this? Surely there is some way to test that the optional fields are there or not.

Just to reiterate, the fields are not showing up, they do not show as null, they are not there.

Thanks in advance for any help.

like image 242
dfowler7437 Avatar asked Nov 13 '22 19:11

dfowler7437


1 Answers

What does coords return? I find it hard to believe that the altitude is not even available, because it's a getter. Maybe the whole coords (i.e. the Coordinates object) is null?

Try:

if (solution.coords is! Coordinates) {
    print('No coords!');
}

The exception is thrown because it's unimplemented: http://src.chromium.org/multivm/trunk/webkit/Source/WebCore/bindings/dart/custom/DartCoordinatesCustom.cpp

If you run as JavaScript, things work well, because it does not use the Dart VM.

like image 163
Kai Sellgren Avatar answered Nov 23 '22 23:11

Kai Sellgren