-
Notifications
You must be signed in to change notification settings - Fork 6
MartinHo12 edited this page Jan 6, 2014
·
10 revisions
Taking ChromeSerial as an example, the following code will give you an error:
var serial = new ChromeSerial();
serial.getPorts().then((List<String> ports) => print("Ports Available: $ports"));
ChromeSerial does not have a default constructor. This is because we are following the existing chrome apps/extensions javascript convention for a singleton design pattern on each api namespace, so no constructor is needed for the exposed API. Use following code instead:
import 'package:chrome_gen/chrome_app.dart' as chrome;
main() {
chrome.serial.getPorts().then((ports) {
print("${ports.length} ports available");
ports.forEach((p) => print(' ${p}');
});
}
If you use the Editor to launch an html file, it'll run as a normal web application and none of the Chrome APIs will be available. You must right-click on the manifest.json
file and choose 'Run as Chrome App'.
ArrayBuffer buf = new chrome.ArrayBuffer.fromString(foo);