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:
- Exact path match – Compares against each asset’s full path.
- Filename match – Matches only the filename if the full path fails.
- Normalized path match – Handles platform-specific differences
like
file://
prefixes and\
vs/
. - Suffix match – Matches by the tail end of the path if needed.
- 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
-
- Object
- AssetPathResource
- DefaultAssetPathResource
- Available extensions
Constructors
- DefaultAssetPathResource(String path)
- Default implementation of AssetPathResource that resolves assets from the runtime environment using a path or filename.
Properties
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