如何在同一个类中导入dart:html&dart:io?

如何在同一个类中导入dart:html&dart:io?,第1张

概述下面的代码“看起来正确”,它编译,但不运行,失败的控制台消息: Cannot load Dart script dart:io Failed to load resource 如果我注释掉#import(‘dart:io’);我错了,我得到一个编译错误,但它启动,直到我按下按钮,我是否收到运行时错误: Internal error: ‘http://127.0.0.1:3030/home/davi 下面的代码“看起来正确”,它编译,但不运行,失败的控制台消息:

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();}
解决方法 dart:HTML是客户端库,而dart:io是服务器端库. dart:HTML利用了浏览器的功能,但dart:io利用了受浏览器安全性限制的功能(例如文件系统访问等).

可能是时候你可以在服务器上使用dart:HTML,使用“模拟”浏览器,这可能对单元测试等有用,但你还不能这样做.

总结

以上是内存溢出为你收集整理的如何在同一个类中导入dart:html&dart:io?全部内容,希望文章能够帮你解决如何在同一个类中导入dart:html&dart:io?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1138254.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存