PubPackageMeta
Logodartdoc_modern

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
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
String get description;

dir final inherited#

final Folder dir

Inherited from PackageMeta.

Implementation
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
@override
int get hashCode => _pathContext.hash(_pathContext.absolute(dir.path));

homepage no setter inherited#

String get homepage

Inherited from PackageMeta.

Implementation
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
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
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
bool get isValid => getInvalidReasons().isEmpty;

name no setter inherited#

String get name

Inherited from PackageMeta.

Implementation
String get name;

repository no setter inherited#

String get repository

Inherited from PackageMeta.

Implementation
String get repository;

requiresFlutter no setter inherited#

bool get requiresFlutter

Inherited from PackageMeta.

Implementation
bool get requiresFlutter;

resolvedDir late final#

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

resourceProvider final inherited#

final ResourceProvider resourceProvider

Inherited from PackageMeta.

Implementation
final ResourceProvider resourceProvider;

runtimeType no setter inherited#

Type get runtimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
external Type get runtimeType;

version no setter inherited#

String get version

Inherited from PackageMeta.

Implementation
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
List<String> getInvalidReasons();

getReadmeContents() inherited#

File? getReadmeContents()

Inherited from PackageMeta.

Implementation
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:

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:

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
@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
@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
@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
@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
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) {
          try {
            return _FilePackageMeta(dir, resourceProvider);
          } on YamlException {
            &#47;&#47; Skip scaffold&#47;template pubspec files that are not valid YAML
            &#47;&#47; for the current package scan, and continue walking up to the
            &#47;&#47; nearest real package root.
            continue;
          } catch (error) {
            if (error is TypeError) {
              continue;
            }
            rethrow;
          }
        }
      }
    }
    return null;
  });
}

fromElement()#

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

Use this instead of fromDir where possible.

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

  if (sourceFile.exists) {
    return PubPackageMeta.fromDir(sourceFile.parent, resourceProvider);
  }

  var current = pathContext.dirname(sourcePath);
  while (current.isNotEmpty && current != pathContext.dirname(current)) {
    final folder = resourceProvider.getFolder(current);
    if (folder.exists) {
      return PubPackageMeta.fromDir(folder, resourceProvider);
    }
    current = pathContext.dirname(current);
  }

  return null;
}

fromFilename()#

PackageMeta ? fromFilename ( String filename , ResourceProvider resourceProvider )
Implementation
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
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];
}