neterror / dart_leaflet

dart JS interop package to wrap leaflet.js library in dart web application
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

JS methods always return NativeJavaScriptObject instead of the declared dart type #1

Open neterror opened 5 years ago

neterror commented 5 years ago

When JS method returns an object, its type is NativeJavaScriptObject instead of the declared Dart type. For example in CircleMarker, the method getLatLng is declared as: external LatLng getLatLng();

var c = CircleMarker(); var pos = c.getLatLng(); // pos type is NativeJavaScriptObject instead of LatLng

getLatLng() is declared to return LatLng, but it returns NativeJavaScriptObject. This object fails the type checks if it is passed to function that expects LatLng.

var positions = []; positions.add(pos); // error! Type mismatch

bkraszewski commented 4 years ago

@neterror ran into a similar problem, have you solved it?

neterror commented 4 years ago

The solution was to declare the types of data, returned from javascript as dynamic, instead of specific dart type.