下面的代码“看起来正确”,它编译,但不运行,失败的控制台消息:
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(); }
解决方法
原文地址:https://www.jb51.cc/html/226117.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。