所以我有两个dart文件 - 一个定义入口点Main(),另一个是我创建的类。主文件#imports dart:html和#sources我的类。我的类使用dart:html命名空间,如果我不#import它,Dart编辑器将显示错误。但是,如果我#import dart:html,我的类将无法编译,因为Main文件已经存在,但是在没有#import的情况下编译很好。有没有办法安抚dart编辑器,或者这是dart编辑器如何解析命名空间的已知问题?
答案 0 :(得分:4)
您应该只进行一次导入,然后从主文件中获取程序文件。像这样:
<强> main.dart 强>
#import("dart:html");
#source("program.dart");
main() {
var program = new Program();
program.run();
}
<强> program.dart 强>
class Program {
run() {
var elm = new Element.html("<p>hello world</p>");
document.body.nodes.add(elm);
}
}
一定能奏效。