PackageInfo constructor

PackageInfo(
  1. String name
)

Creates a PackageInfo for a single package by name.

Best for: Development environments where the analyzer plugin is active.

The name must exactly match the name field in the package's pubspec.yaml. The analyzer plugin will automatically provide the package path and context.

Example:

// For a pubspec.yaml with: name: my_app
final info = PackageInfo('my_app');

Note: This won't work in CI/CD environments without the analyzer plugin. Use PackageInfo.path instead for those scenarios.

Parameters:

  • name: The package name from pubspec.yaml

Implementation

factory PackageInfo(String name) {
  if (name.contains('/') || name.contains('\\')) {
    throw ArgumentError.value(
      name,
      'name',
      'Must be a package name, not a path. Use PackageInfo.path() for paths, '
          'e.g., PackageInfo.path("/workspace/my_app") for CI/CD environments.',
    );
  }
  return PackageInfo._([name]);
}