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();
}
Although no production browsers can execute Dart code directly, all modern browsers can execute Dart code that's been compiled to JavaScript.
Digital Publishing Platform & Software for Magazines,Catalogs,Brochures,FlipBook & More.
dart:html
is a client side library, whereas dart:io
is a server side library. dart:html
makes use of features of the browser, but dart:io
makes use of features that are restricted by browser security (such as file system access an so-on).
It may be that the time comes that you can use dart:html
on the server, with a "mocked" browser, which could be useful for unit testing and the like, but you can't do that yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With