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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With