下面的代码“看起来正确”,它编译,但不运行,失败的控制台消息:
Cannot load Dart script dart:io
Failed to load resource
如果我注释掉#import(‘dart:io’);我错了,我得到一个编译错误,但它启动,直到我按下按钮,我是否收到运行时错误:
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,‘/’);
……这是预期的.
所以我的问题是:如何导入dart:html&飞镖:io在同一个班级?
#import('dart:html'); #import('dart:io'); class htmlIO { ButtonElement _aButton; htmlIO() { } void handlePress(Event e) { var connection = new HttpClient().get('www.google.com','/'); 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(); }