asset_tree_shaker library

Asset Tree Shaker - Detect and remove unused assets from Flutter projects.

This library provides tools to:

  • Discover all declared assets in pubspec.yaml
  • Scan Dart files using AST analysis to find asset references
  • Compare declared vs used assets to identify orphans
  • Generate reports and optionally clean unused assets

Classes

AnalysisResult
Complete result of analyzing asset usage.
AnalysisSummary
Summary statistics of the analysis.
AnalyzedAsset
Information about a single analyzed asset.
AssetCleaner
Handles cleaning (deleting) unused assets with safety features.
AssetDiscovery
Discovers and enumerates assets declared in pubspec.yaml.
AssetPreview
Preview information for a single asset.
AssetReference
Represents a reference to an asset in source code.
AssetReferenceVisitor
AST visitor that finds asset references in Dart code.
AssetTreeShakerConfig
Configuration for asset tree shaker.
AssetVisitorResult
Result of visiting a Dart AST for asset references.
CleanPreview
Preview of assets that would be deleted.
CleanResult
Result of a clean operation.
ConfigLoader
Loads and parses asset_tree_shaker.yaml configuration files.
DeclaredAsset
Represents a declared asset from pubspec.yaml.
DeletedAsset
Information about a deleted asset.
DynamicAssetReference
Represents a dynamic asset reference that cannot be statically resolved.
DynamicUsageWarning
Warning about dynamic asset usage.
FailedDeletion
Information about a failed deletion.
GraphAnalyzer
Analyzes asset usage by comparing declared assets against found usages.
KeepAsset
Annotation to mark an asset as required, preventing tree-shaker removal.
KeepAssets
Annotation to mark multiple assets as required.
PatternMatcher
Utility class for matching asset paths against glob patterns.
PreserveAsset
Annotation to preserve all assets matching a pattern.
ReportGenerator
Generates reports from analysis results.
RestoreResult
Result of a restore operation.
ScanError
Error encountered during file scanning.
UsageScanner
Scans Dart files to find asset references using AST analysis.
UsageScanResult
Result of scanning for asset usages.

Enums

AssetReferenceType
Type of asset reference.
AssetStatus
Categorization of an asset's usage status.
ReportFormat
Supported report output formats.

Extensions

ReportFormatExtension on ReportFormat
Extension to parse report format from string.

Exceptions / Errors

AssetDiscoveryException
Exception thrown when asset discovery fails.
CleanerException
Exception thrown by the cleaner.
ConfigurationException
Exception thrown when configuration parsing fails.