Suppose we'd like to wrap the Google Maps JavaScript API google.maps
:
@JS('google.maps')
library maps;
import "package:js/js.dart";
@JS()
class Map {
external Map(Location location);
external Location getLocation();
}
We now have the Map Dart class which corresponds to the JavaScript google.maps.Map
class.
Running new Map(someLocation)
in Dart will invoke new google.maps.Map(location)
in JavaScript.
Note that you don't have to name your Dart class the same as the JavaScript class:
@JS("LatLng")
class Location {
external Location(num lat, num lng);
}
The Location
Dart class corresponds to the google.maps.LatLng
class.
Using inconsistent names is discouraged as they can create confusion.