Template class abstract interface

Represents an abstract template source that can be rendered by a TemplateRenderer using a set of dynamic attributes or a TemplateContext.

A Template provides a path or location to the template content, along with a map of attributes to inject during rendering. This abstraction allows templates to be sourced from files, memory, network, or other storage mechanisms.

Responsibilities

  • Provide the template location or path as a string, which will be loaded and rendered by the template renderer.
  • Supply a map of attributes (Map<String, Object?>) for variable substitution and evaluation.
  • Serve as an abstraction over different template sources (file system, asset bundle, or dynamic content).

Design Notes

  • Implementations may load the template content lazily based on the path.
  • Attributes may be evaluated lazily, cached, or computed dynamically.
  • Implementations must ensure getAttributes() never returns null.

Example Implementation

class FileTemplate implements Template {
  final String _path;
  final Map<String, Object?> _attributes;

  FileTemplate(this._path, [this._attributes = const {}]);

  @override
  String getLocation() => _path;

  @override
  Map<String, Object?> getAttributes() => _attributes;
}

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

getAttributes() Map<String, Object?>
Returns a map of dynamic attributes to inject into the template.
getLocation() String
Returns the path or location of the template as a string.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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