I am writing a simple application to learn some basic Dart programming but I can't work out the structure and inclusions - I get a Duplicate class Point
First of all, I have my main class I called MouseTrack. It initializes the list and will have a loop.
#import('dart:html');
#import('Eye.dart');
class MouseTrace {
List<Eye> eyes;
...
}
Secondly, I have a class called Eye, which is supposed to hold information of of an eye as a circle. It's quite simple:
#library('app:eye');
#import('dart:html'); // without this one, I get no error but I want to have it to use CanvasRenderingContext2D
#import('Point.dart');
class Eye {
Point position;
num radius;
Eye() :
position = new Point() {
}
void draw(CanvasRenderingContext2D context) {
// draws a circle
}
}
And finally Point:
#library('app:point');
class Point {
num x, y;
Point(this.x, this.y);
}
What I want to achieve is 3 separate classes - main, Eye and Point, so I can have instances of Eye in main (for simplicity & nice model) and instances of Point in Eye (for storing position). At least that's how I'm used to doing.
P.S I know I can skip types but I want it there and I guess it's a problem with inclusions rather than the language (and want to fix it so I know how to do it properly). P.S.S. I have cut off some code so that you don't have to read everything but, if you want, I will post it all.
Problem lies in the
app:eye
library (in theEye.dart
file). You importdart:html
andapp:point
libraries, but both of them define aPoint
class. This situation is invalid. You can solve it either by not importingdart:html
at all, if you don't need it, or prefixing one of those imports:In this case, you will have to refer to names from
dart:html
by using ahtml.
prefix. In your case, if you want to use theCanvasRenderingContext2D
class, you will have to writehtml.CanvasRenderingContext2D
instead.