The code below "looks right", it compiles, but does not run, failing with the console message:
Cannot load Dart script dart:io
Failed to load resource
If I comment out the #import('dart:io');
, wrong I believe, I get a compilation error, but it launches and not until I press the button, do I get the runtime error:
Internal error: 'http://127.0.0.1:3030/home/david/dart/samples/htmlIO/htmlIO.dart': Error: line 13 pos 26: type 'HttpClient' is not loaded
var connection = new HttpClient().get('www.google.com', 80, '/');
... which is expected.
So my question is: How do I import dart:html & dart:io in the same class?
#import('dart:html');
#import('dart:io');
class htmlIO {
ButtonElement _aButton;
htmlIO() {
}
void handlePress(Event e) {
var connection = new HttpClient().get('www.google.com', 80, '/');
write('made it');
}
void run() {
_aButton = document.query("#aButton");
_aButton.on.click.add(handlePress);
write("Hello World!");
}
void write(String message) {
// the HTML library defines a global "document" variable
document.query('#status').innerHTML = message;
}
}
void main() {
new htmlIO().run();
}