[英]Dart library visibility
My Dart app has the following structure: 我的Dart应用具有以下结构:
myapp/
pubspec.yaml
pubspec.lock
asset/
...
web/
logging/
Logger.dart
LogLevel.dart
...other packages
Where the 2 shown Dart files are: 其中显示的2个Dart文件是:
LogLevel.dart
: LogLevel.dart
:
library logging;
class LogLevel {
static const TRACE = const LogLevel._(0);
static const INFO = const LogLevel._(1);
static const ERROR = const LogLevel._(2);
static get values => [TRACE, INFO, ERROR];
final int value;
const LogLevel._(this.value);
}
Logger.dart
: Logger.dart
:
library logging; // <== compiler error!?!
import "package:logging/LogLevel.dart";
class Logger {
// ...
}
I figured since I put the two classes into a logging
library/package together, that they would be visible to one another. 自从将这两个类放到一个
logging
库/程序包中后,我就认为它们对彼此是可见的。 But that's not the case! 但是事实并非如此! Instead on the
import
statement I get the following compiler error: 相反,在
import
语句中,出现以下编译器错误:
Target of URI does not exist: 'package:logging/LogLevel.dart'
URI的目标不存在:“ package:logging / LogLevel.dart”
What's going on here? 这里发生了什么? How should I be packaging/library-ing my types differently so that they'll be visible to one another?
我应该如何不同地包装/存储我的类型,以便彼此可见?
You can import them through their relative path without referring to the package: 您可以通过它们的相对路径导入它们,而无需参考软件包:
import 'LogLevel.dart';
If you do want to import them as packages, they need to be under the lib
folder. 如果确实要将它们作为软件包导入,则它们必须位于
lib
文件夹下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.