IAmYourFaja
IAmYourFaja

Reputation: 56934

Dart library visibility

My Dart app has the following structure:

myapp/
    pubspec.yaml
    pubspec.lock
    asset/
        ...
    web/
        logging/
            Logger.dart
            LogLevel.dart
        ...other packages

Where the 2 shown Dart files are:

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:

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. But that's not the case! Instead on the import statement I get the following compiler error:

Target of URI does not exist: '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?

Upvotes: 1

Views: 713

Answers (1)

Pixel Elephant
Pixel Elephant

Reputation: 21403

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.

Upvotes: 1

Related Questions