Skip to content

PubPackageMeta abstract

abstract class PubPackageMeta extends PackageMeta

Default implementation of PackageMeta depends on pub packages.

Inheritance

Object → PackageMetaPubPackageMeta

Constructors

PubPackageMeta()

PubPackageMeta(Folder dir, ResourceProvider resourceProvider)
Implementation
dart
PubPackageMeta(super.dir, super.resourceProvider);

Properties

description no setter inherited

String get description

The package description from pubspec.yaml, or an empty string if not available.

Inherited from PackageMeta.

Implementation
dart
String get description;

dir final inherited

final Folder dir

Inherited from PackageMeta.

Implementation
dart
final Folder dir;

hashCode no setter inherited

int get hashCode

The hash code for this object.

A hash code is a single integer which represents the state of the object that affects operator == comparisons.

All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).

If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.

Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.

Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.

If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.

Inherited from PackageMeta.

Implementation
dart
@override
int get hashCode => _pathContext.hash(_pathContext.absolute(dir.path));

homepage no setter inherited

String get homepage

Inherited from PackageMeta.

Implementation
dart
String get homepage;

hostedAt no setter inherited

String? get hostedAt

The hostname that the package is hosted at, usually 'pub.dev', or null if not a hosted pub package.

Inherited from PackageMeta.

Implementation
dart
String? get hostedAt;

isSdk no setter inherited

bool get isSdk

Whether this represents a 'Dart' SDK.

A package can be part of Dart and Flutter at the same time, but if this is part of a Dart SDK, sdkType should never return null.

Inherited from PackageMeta.

Implementation
dart
bool get isSdk;

isValid no setter inherited

bool get isValid

Whether this is a valid package (valid enough to generate docs).

Inherited from PackageMeta.

Implementation
dart
bool get isValid => getInvalidReasons().isEmpty;

name no setter inherited

String get name

Inherited from PackageMeta.

Implementation
dart
String get name;

repository no setter inherited

String get repository

Inherited from PackageMeta.

Implementation
dart
String get repository;

requiresFlutter no setter inherited

bool get requiresFlutter

Inherited from PackageMeta.

Implementation
dart
bool get requiresFlutter;

resolvedDir late final

final late String resolvedDir
Implementation
dart
@override
late final String resolvedDir = dir.resolveSymbolicLinksSync().path;

resourceProvider final inherited

final ResourceProvider resourceProvider

Inherited from PackageMeta.

Implementation
dart
final ResourceProvider resourceProvider;

runtimeType no setter inherited

Type get runtimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

version no setter inherited

String get version

Inherited from PackageMeta.

Implementation
dart
String get version;

Methods

getInvalidReasons() inherited

List<String> getInvalidReasons()

The list of reasons this package is invalid.

If the list is empty, this package is valid.

Inherited from PackageMeta.

Implementation
dart
List<String> getInvalidReasons();

getReadmeContents() inherited

File? getReadmeContents()

Inherited from PackageMeta.

Implementation
dart
File? getReadmeContents();

noSuchMethod() inherited

dynamic noSuchMethod(Invocation invocation)

Invoked when a nonexistent method or property is accessed.

A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).

Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.

A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:

dart
class MockList<T> implements List<T> {
  noSuchMethod(Invocation invocation) {
    log(invocation);
    super.noSuchMethod(invocation); // Will throw.
  }
}
void main() {
  MockList().add(42);
}

This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.

If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.

The default behavior is to throw a NoSuchMethodError.

Inherited from Object.

Implementation
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);

sdkType() override

String? sdkType(String? flutterRootPath)

Returns 'Dart' or 'Flutter' (preferentially, 'Flutter' when the answer is "both"), or null if this package is not part of an SDK.

Implementation
dart
@override
String? sdkType(String? flutterRootPath) {
  if (flutterRootPath != null) {
    var flutterPackages = _pathContext.join(flutterRootPath, 'packages');
    var flutterBinCache = _pathContext.join(flutterRootPath, 'bin', 'cache');

    &#47;&#47;&#47; Don't include examples or other non-SDK components as being the
    &#47;&#47;&#47; "Flutter SDK".
    var canonicalizedDir = _pathContext
        .canonicalize(resourceProvider.pathContext.absolute(dir.path));
    if (_pathContext.isWithin(flutterPackages, canonicalizedDir) ||
        _pathContext.isWithin(flutterBinCache, canonicalizedDir)) {
      return 'Flutter';
    }
  }
  return isSdk ? 'Dart' : null;
}

toString() inherited

String toString()

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Inherited from PackageMeta.

Implementation
dart
@override
String toString() => name;

Operators

operator ==() inherited

bool operator ==(Object other)

The equality operator.

The default behavior for all Objects is to return true if and only if this object and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.

If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.

Inherited from PackageMeta.

Implementation
dart
@override
bool operator ==(Object other) =>
    other is PackageMeta && _pathContext.equals(dir.path, other.dir.path);

Static Methods

fromDir()

PackageMeta? fromDir(Folder folder, ResourceProvider resourceProvider)

This factory is guaranteed to return the same object for any given dir.absolute.path. Multiple dir.absolute.paths will resolve to the same object if they are part of the same package. Returns null if the directory is not part of a known package.

Implementation
dart
static PackageMeta? fromDir(
    Folder folder, ResourceProvider resourceProvider) {
  var pathContext = resourceProvider.pathContext;
  folder = resourceProvider.getFolder(pathContext.absolute(folder.path));
  if (!folder.exists) {
    throw PackageMetaFailure(
      'fatal error: unable to locate the input directory at '
      "'${folder.path}'.",
    );
  }

  return _packageMetaCache.putIfAbsent(pathContext.absolute(folder.path), () {
    &#47;&#47; There are pubspec.yaml files inside the SDK.  Ignore them.
    var parentSdkDir = sdkDirParent(folder, resourceProvider);
    if (parentSdkDir != null) {
      return _SdkMeta(parentSdkDir, resourceProvider);
    } else {
      for (var dir in folder.withAncestors) {
        var pubspec = resourceProvider
            .getFile(pathContext.join(dir.path, 'pubspec.yaml'));
        if (pubspec.exists) {
          return _FilePackageMeta(dir, resourceProvider);
        }
      }
    }
    return null;
  });
}

fromElement()

PackageMeta? fromElement(
  LibraryElement libraryElement,
  String sdkDir,
  ResourceProvider resourceProvider,
)

Use this instead of fromDir where possible.

Implementation
dart
static PackageMeta? fromElement(LibraryElement libraryElement, String sdkDir,
    ResourceProvider resourceProvider) {
  if (libraryElement.isInSdk) {
    return PubPackageMeta.fromDir(
        resourceProvider.getFolder(sdkDir), resourceProvider);
  }
  return PubPackageMeta.fromDir(
      resourceProvider
          .getFile(resourceProvider.pathContext
              .canonicalize(libraryElement.firstFragment.source.fullName))
          .parent,
      resourceProvider);
}

fromFilename()

PackageMeta? fromFilename(String filename, ResourceProvider resourceProvider)
Implementation
dart
static PackageMeta? fromFilename(
    String filename, ResourceProvider resourceProvider) {
  return PubPackageMeta.fromDir(
      resourceProvider.getFile(filename).parent, resourceProvider);
}

sdkDirParent()

Folder? sdkDirParent(Folder folder, ResourceProvider resourceProvider)

If folder is inside a Dart SDK, returns the directory of the SDK, and null otherwise.

Implementation
dart
static Folder? sdkDirParent(
    Folder folder, ResourceProvider resourceProvider) {
  var pathContext = resourceProvider.pathContext;
  var dirPathCanonical = pathContext.canonicalize(folder.path);
  if (!_sdkDirParent.containsKey(dirPathCanonical)) {
    _sdkDirParent[dirPathCanonical] = null;
    for (var dir in folder.withAncestors) {
      if (_sdkDirFilePaths.every((List<String> l) {
        return l.any((f) =>
            resourceProvider.getFile(pathContext.join(dir.path, f)).exists);
      })) {
        _sdkDirParent[dirPathCanonical] = dir;
        break;
      }
    }
  }
  return _sdkDirParent[dirPathCanonical];
}