PackageAssetReader class

Resolves using a PackageConfig before reading from the file system.

For a simple implementation that uses the current isolate's package resolution logic (i.e. whatever you have generated in .dart_tool/package_config.json in most cases), use currentIsolate:

var assetReader = await PackageAssetReader.currentIsolate();


PackageAssetReader(PackageConfig _packageConfig, [String? _rootPackage])
Wrap a PackageConfig to identify where files are located.
PackageAssetReader.forPackageRoot(String packageRoot, [String? rootPackage])
A PackageAssetReader with a single packageRoot configured.
PackageAssetReader.forPackages(Map<String, String> packageToPath, [String? rootPackage])
Returns a PackageAssetReader with a simple packageToPath mapping.


hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


canRead(AssetId id) Future<bool>
Indicates whether asset at id is readable.
digest(AssetId id) Future<Digest>
Returns a Digest representing a hash of the contents of id.
findAssets(Glob glob, {String? package}) Stream<AssetId>
Returns all readable assets matching glob under the current package.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
readAsBytes(AssetId id) Future<List<int>>
Returns a Future that completes with the bytes of a binary asset.
readAsString(AssetId id, {Encoding encoding = utf8}) Future<String>
Returns a Future that completes with the contents of a text asset.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.

Static Methods

currentIsolate({String? rootPackage}) Future<PackageAssetReader>
A reader that can resolve files known to the current isolate.