Dart中的重复类 [英] Duplicate Class in Dart
问题描述
我在写一个简单的应用程序来学习一些基本的Dart编程,但是我不能解决结构和包含 - 我得到一个复制类Point
all,我有我的主类我叫 MouseTrack 。它初始化列表,并有一个循环。
import('dart:html');
#import('Eye.dart');
class MouseTrace {
List< Eye>眼睛;
...
}
其次, > Eye ,它应该将眼睛的信息保持为圆形。很简单:
#library('app:eye');
#import('dart:html'); //没有这个,我没有错误,但我想让它使用CanvasRenderingContext2D
#import('Point.dart');
class Eye {
点位置;
num radius;
Eye():
position = new Point(){
}
void draw(CanvasRenderingContext2D context){
//一个圆
}
}
最后 >:
#library('app:point');
class Point {
num x,y;
Point(this.x,this.y);
}
我想要实现的是3个单独的类 - main , ,因此我可以在 模型)和点中的点(用于存储位置)的实例。至少这是我习惯了。
PS我知道我可以跳过类型,但我想要它在那里,我想这是一个问题,包括而不是语言(并希望修复它,所以我知道如何做它正确)。
P.S.S.我已经切断了一些代码,所以你不必读取一切,但如果你想,我会发布所有。
问题出在 app:eye
库(在 Eye.dart
文件中)。您导入 dart:html
和 app:point
库,但它们都定义了
类。此情况无效。你可以通过不导入 dart:html
,如果你不需要它,或者为这些导入之一加上前缀来解决它:
#import('dart:html',prefix:'html');
#import('Point.dart');
在这种情况下,您必须引用 dart:html
,使用 html。
前缀。在你的情况下,如果你想使用 CanvasRenderingContext2D
类,你将不得不写 html.CanvasRenderingContext2D
。 / p>
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 the Eye.dart
file). You import dart:html
and app:point
libraries, but both of them define a Point
class. This situation is invalid. You can solve it either by not importing dart:html
at all, if you don't need it, or prefixing one of those imports:
#import('dart:html', prefix: 'html');
#import('Point.dart');
In this case, you will have to refer to names from dart:html
by using a html.
prefix. In your case, if you want to use the CanvasRenderingContext2D
class, you will have to write html.CanvasRenderingContext2D
instead.
这篇关于Dart中的重复类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!