下面的代码"看起来正确",它编译,但不运行,失败的控制台消息:
无法加载Dart脚本dart:io
无法加载资源
如果我注释掉了#import('dart:io');
,错误我相信,我得到一个编译错误,但它启动,直到我按下按钮,我是否得到运行时错误:
内部错误:'http://127.0.0.1:3030/home/david/dart/samples/htmlIO/htmlIO.dart':错误:第13行pos 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();
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*ett 10
dart:html
是一个客户端库,而是dart:io
一个服务器端库. dart:html
利用浏览器的功能,但dart:io
利用受浏览器安全性限制的功能(例如文件系统访问等).
可能是您可以dart:html
在服务器上使用"模拟"浏览器的时间,这可能对单元测试等有用,但您还不能这样做.
归档时间: |
|
查看次数: |
2441 次 |
最近记录: |