dart 是否有某种别名来解决这样的命名冲突?
library flutterfly;
import 'dart:ui';
class Color {
Color._();
// Color should be the class from dart:ui instead of itself.
static Color white() {
return Color(#FFFFFFFF);
}
}
import 'dart:ui' as ui;
class Color {
Color._();
static ui.Color white() {
return ui.Color(0xFFFFFFFF);
}
}
也就是说,因为导入您的
flutterfly
库的人可以选择他们想要的任何库前缀(如果有),因此添加您自己的 Color
类用作命名空间并不是很有用,并且它的存在可能会导致冲突任何使用它的东西。 effective Dart 建议不要使用仅包含静态成员的类。对于此示例,您可以改用顶级函数。