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