Skip to content
MartinHo12 edited this page Jan 6, 2014 · 10 revisions

1. How to create a chrome_gen class instance?

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}');
  });
}

2. How to run a Chrome App from the Dart Editor?

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'.

3. How to convert a String to an ArrayBuffer ?

ArrayBuffer buf = new chrome.ArrayBuffer.fromString(foo);