An abstract representation of a resource that wraps either:
- Raw textual content (e.g., JSON, YAML, Dart code, properties).
- An Asset object.
This abstraction allows working uniformly with both inline content and
file-based assets. The actual implementation is provided by the private
class _AssetResource.
Example: Creating from raw content
final resource = AssetResource('{ "name": "example" }');
print(resource.source); // prints the JSON string
Example: Creating from an Asset
final asset = FileAsset('/path/to/config.yaml');
final resource = AssetResource(asset);
print(resource.source); // prints the FileAsset instance
Extension Strategies
Developers can plug in custom extension strategies to determine the file extension dynamically:
AssetResource.registerExtensionStrategy((source) {
if (source is String && source.endsWith('.conf')) {
return 'conf';
}
return null;
});
Content Detectors
Similarly, content detectors decide whether a String is inline content
or a path:
AssetResource.registerContentDetector((source) {
if (source is String && source.contains('{')) return true;
return false;
});
- Inheritance
-
- Object
- BaseDeclaration
- Asset
- AssetResource
Constructors
- AssetResource(Object source)
-
Factory constructor for creating an AssetResource.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString.inherited -
getContentAsString(
) → String -
Example
inherited
-
getContentBytes(
) → Uint8List -
Returns the binary content of the asset as a Uint8List.
inherited
-
getFileName(
) → String -
Returns the name of the file represented by this asset.
inherited
-
getFilePath(
) → String -
Returns the full path to the file on disk or in the package.
inherited
-
getPackageName(
) → String? -
Returns the name of the package from which this asset originates.
inherited
-
getSource(
) → Object - The underlying source of this resource.
-
getUniqueName(
) → String -
Returns a unique name for the asset, combining the package name and
the base file name (without extension).
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, Object> -
Serializes this declaration into a JSON-compatible map.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
determineExtension(
Object source) → String? -
Determines the file extension for a given
source. -
getIsContent(
Object source) → bool -
Determines whether a given
sourceshould be treated as inline content. -
registerContentDetector(
AssetResourceContentDetector detector) → void - Registers a new content detector.
-
registerExtensionStrategy(
AssetResourceExtensionStrategy strategy) → void - Registers a new extension strategy.