DefaultVariableResolver class final
Default implementation of TemplateVariableResolver, providing variable resolution from a flat or nested map of values.
DefaultVariableResolver supports:
- Resolving simple variables:
'name' - Resolving nested variables using dot notation:
'user.address.city' - Converting values to string representations for template rendering.
Design Notes
- Nested variables are resolved recursively through
Map<String, Object?>. - Supports standard types:
String,bool,List,Map, and general objects. - Returns empty string
''fornullvalues to avoid template errors.
Usage Example
final resolver = DefaultVariableResolver({
'name': 'Alice',
'user': {
'address': {'city': 'Paris', 'zip': 75000}
},
'tags': ['dart', 'flutter']
});
print(resolver.resolve('name')); // 'Alice'
print(resolver.resolve('user.address.city')); // 'Paris'
print(resolver.resolve('tags')); // 'dart, flutter'
print(resolver.resolve('unknown')); // ''
- Implemented types
Constructors
- DefaultVariableResolver()
- Creates a new DefaultVariableResolver with the given variable map.
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
variablename to its string representation.override -
setVariables(
Map< String, Object?> variables) → void -
Sets multiple variables at once.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited