So I have two dart files -- One defines the entry-point Main() and the other is a class I've created. The Main file #imports dart:html and #sources my class. My class uses the dart:html namespace, and Dart Editor will display errors if I don't #import it. However, my class will fail to compile if I #import dart:html since the Main file already does, but compiles fine without the #import. Is there a way to appease the dart editor, or is this a known issue with how the dart editor resolves namespaces?
2
votes
1 Answers
4
votes
You should only do the import once and then source your program files from your main file. Something like this:
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);
}
}
should definitely work.