Page 28 - Dart Language
P. 28
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.
Passing object literals
It's common practice in JavaScript to pass object literals to functions:
// JavaScript
printOptions({responsive: true});
Unfortunately we cannot pass Dart Map objects to JavaScript in these cases.
What we have to do is create a Dart object that represents the object literal and contains all of its
fields:
// Dart
@JS()
@anonymous
class Options {
external bool get responsive;
external factory Options({bool responsive});
}
Note that the Options Dart class doesn't correspond to any JavaScript class. As such we must
mark it with the @anonymous annotation.
Now we can create a stub for the original printOptions function and call it with a new Options
object:
// Dart
@JS()
external printOptions(Options options);
printOptions(new Options(responsive: true));
Read Dart-JavaScript interoperability online: https://riptutorial.com/dart/topic/9240/dart-javascript-
interoperability
https://riptutorial.com/ 23

