TemplateVariableResolver class abstract interface

Resolves template variable names into their string representations at runtime during template rendering.

TemplateVariableResolver provides a flexible mechanism to supply values for placeholders in templates. It abstracts how variables are looked up, computed, or fetched from external sources.

Responsibilities

  • Resolve a variable name to a string that can be substituted into a template.
  • Support dynamic or computed variable resolution.
  • Optionally allow bulk setting of variables for later resolution.

Design Notes

  • Implementations may use an internal map, lazy computation, or integrate with external services.
  • Should handle unknown or missing variables gracefully:
    • Return an empty string,
    • Provide a default value, or
    • Throw a descriptive exception, depending on the use case.
  • Useful in combination with TemplateContext and TemplateRenderer.

Example Implementation

class MapVariableResolver implements TemplateVariableResolver {
  final Map<String, Object?> _variables;

  MapVariableResolver([Map<String, Object?>? variables])
      : _variables = variables ?? {};

  @override
  String resolve(String variable) => _variables[variable]?.toString() ?? '';

  @override
  void setVariables(Map<String, Object?> variables) {
    _variables.clear();
    _variables.addAll(variables);
  }
}

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolve(String variable) String
Resolves the given variable name to its string representation.
setVariables(Map<String, Object?> variables) → void
Sets multiple variables at once.
toString() String
A string representation of this object.
inherited

Operators

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