DefaultAssetPathResource class final

Default implementation of AssetPathResource that resolves assets from the runtime environment using a path or filename.

This class attempts to locate an asset in multiple ways:

  1. Exact path match – Compares against each asset’s full path.
  2. Filename match – Matches only the filename if the full path fails.
  3. Normalized path match – Handles platform-specific differences like file:// prefixes and \ vs /.
  4. Suffix match – Matches by the tail end of the path if needed.
  5. Single filename candidate – If exactly one candidate matches the filename.

Once resolved, the asset is cached internally for efficient access.

Example

final resource = DefaultAssetPathResource("assets/config/settings.yaml");

if (resource.exists()) {
  print("Found: ${resource.getFileName()}");
  final bytes = resource.getContentBytes();
  print("Content length: ${bytes.length}");
} else {
  print("Asset not found");
}
Inheritance
Available extensions

Constructors

DefaultAssetPathResource(String path)
Default implementation of AssetPathResource that resolves assets from the runtime environment using a path or filename.

Properties

hashCode int
The hash code for this object.
no setterinherited
path String
The original path string used to resolve this resource.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

exists() bool
Checks whether the underlying resource exists.
override
get([Supplier<Exception>? throwIfNotFound]) Asset
Retrieves the asset represented by this resource.
override
getContentAsString() String

Available on Asset, provided by the AssetExtension extension

Extension methods for Asset objects.
getContentBytes() Uint8List
Returns the binary content of the asset (same as _contentBytes).
override
getFileName() String
Returns the name of the file (same as _fileName).
override
getFilePath() String
Returns the full path to the file (same as _filePath).
override
getInputStream() InputStream
Returns a new InputStream to read the underlying content.
override
getPackageName() String?
Returns the name of the originating package (same as _packageName).
override
getResourcePath() String
Returns the underlying file system path for this resource.
inherited
getUniqueName() String
Returns a unique name for the asset, combining the package name and file name.
override
hasExtension(List<String> exts) bool
Checks whether the asset’s path ends with any of the provided extensions.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object>
Serializes this resource to a JSON-encodable map.
override
toString() String
A string representation of this object.
inherited
tryGet([Supplier<Exception>? orElseThrow]) Asset?
Attempts to retrieve the asset safely.
override

Operators

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