【发布时间】:2012-04-15 17:53:44
【问题描述】:
下面的代码“看起来正确”,它编译,但没有运行,控制台消息失败:
无法加载 Dart 脚本 dart:io
加载资源失败
如果我注释掉#import('dart:io');,我相信是错误的,我会收到编译错误,但它会启动,直到我按下按钮,我会收到运行时错误:
内部错误:“http://127.0.0.1:3030/home/david/dart/samples/htmlIO/htmlIO.dart”:错误:第 13 行第 26 行:未加载类型“HttpClient”
var connection = new HttpClient().get('www.google.com', 80, '/');
...这是预期的。
所以我的问题是:如何在同一个类中导入 dart:html 和 dart:io?
#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();
}
【问题讨论】:
标签: dart