DefaultExpressionEvaluator class final

Default implementation of TemplateExpressionEvaluator, capable of evaluating template expressions in a given TemplateContext.

DefaultExpressionEvaluator supports:

  • Logical operators: &&, ||
  • Comparison operators: ==, !=, >, <, >=, <=
  • Nullish coalescing: ??
  • Literal values: strings, numbers, booleans, and null
  • Variable resolution via TemplateVariableResolver

Design Notes

  • Expressions are parsed in a simple recursive manner, handling operator precedence manually (logical operators lowest, then comparison).
  • Returns false on invalid expressions instead of throwing.
  • Supports dot notation for nested variable access (user.address.city).

Usage Example

final context = DefaultTemplateContext({'age': 25});
final evaluator = DefaultExpressionEvaluator();

print(evaluator.evaluate('age >= 18', context)); // true
print(evaluator.evaluate('age < 18 || false', context)); // false
print(evaluator.evaluate('"hello" == "hello"', context)); // true
Implemented types

Constructors

DefaultExpressionEvaluator()
Default implementation of TemplateExpressionEvaluator, capable of evaluating template expressions in a given TemplateContext.
const

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

evaluate(String expression, TemplateContext context) bool
Evaluates the given expression string using the provided context.
override
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