Skip to content
Rashid

Expression Evaluator

High-performance Dart package for evaluating dynamic logical and comparison expressions.

DartOpen SourceAlgorithm

!The Problem

Flutter and Dart applications often need to evaluate business rules (like "IF age > 18 AND status == active") that are defined dynamically (e.g., from a JSON config) rather than hardcoded.

The Solution

Expression Evaluator is a lightweight, secure parser that tokenizes and evaluates these strings at runtime. It supports complex nested logic, types, and custom operators without the overhead of a full scripting engine.

Usage

Ideal for:

  • Dynamic Forms: Show/hide fields based on complex user input.
  • Rule Engines: Filtering data based on server-sent criteria.
  • Feature Flags: Evaluating rollout conditions on the client side.

Technical Details

The package implements a recursive descent parser to handle operator precedence and nested parentheses correctly. It is fully typed and null-safe, ensuring stability in production Flutter apps.

// Example
const expression = "price > 100 AND (category == 'electronics' OR is_sale == true)";
const context = {'price': 150, 'category': 'electronics', 'is_sale': false};

final result = ExpressionEvaluator.eval(expression, context);
// result: true