GenerativeAsset class abstract

Base class representing a resource asset with a no-args constructor.

Designed primarily for code generation scenarios, where subclasses are instantiated reflectively (e.g., via mirrors or generated code).

Subclasses are expected to override the core getters to provide asset metadata and content:

  • _filePath — the asset's relative or absolute path
  • _fileName — the asset's file name
  • _packageName — the package the asset belongs to
  • _contentBytes — the raw byte content of the asset

Generated subclasses typically provide these as final fields for immutable, compile-time-safe assets.

Usage Example

class GeneratedAssetExample extends GenerativeAsset {
  @override
  String getFilePath() => "assets/config.json";

  @override
  String getFileName() => "config.json";

  @override
  String? getPackageName() => "my_package";

  @override
  Uint8List getContentBytes() => Uint8List.fromList([1, 2, 3]);
}

final asset = GeneratedAssetExample();
print(asset.getFilePath()); // "assets/config.json"

Design Notes

  • Must have a no-args constructor to support reflective instantiation.
  • Serves as a base for code-generated asset classes, ensuring a uniform API across all assets.
  • Provides default dummy values in the constructor to satisfy the base Asset class; actual values must be supplied by overriding getters.

See Also

Inheritance

Constructors

GenerativeAsset()
Default no-args constructor.

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, and toString.
inherited
getContentAsString() String
Example
inherited
getContentBytes() Uint8List
Returns the binary content of the asset as a Uint8List.
override
getFileName() String
Returns the name of the file represented by this asset.
override
getFilePath() String
Returns the full path to the file on disk or in the package.
override
getPackageName() String?
Returns the name of the package from which this asset originates.
override
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