Skip to content
pubscout

expressions

0.2.5+3, released a year ago by appsup.be

Parse and evaluate simple Dart and JavaScript like expressions.

WASM-ready
$ flutter pub add expressions
Source repository

What it does

Parses string expressions into an expression object and evaluates them against a provided context of variables and functions. It supports common programming language syntax but does not handle complex blocks of code or control flow statements.

AI-written summary of version 0.2.5+3, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to evaluate user-entered math or logic formulas at runtime.
  • You want to parse simple JSON-like structures or dynamic property lookups.

Skip it when

  • You need a full Dart interpreter supporting control flow, blocks, and statements.
  • You require advanced language features like string interpolation or named parameters out of the box.

Strengths

  • Lightweight parser powered by petitparser.
  • Supports custom evaluators for member expressions and async execution.

Weaknesses

  • Does not support full Dart language constructs, blocks, or control flow statements.
  • Default evaluator cannot handle member expressions without custom implementation.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
4
Expression expression = Expression.parse("cos(x)*cos(x)+sin(x)*sin(x)==1");
var context = {
  "x": pi / 5,
  "cos": cos,
  "sin": sin
};
final evaluator = const ExpressionEvaluator();
var r = evaluator.eval(expression, context);

Alternatives

Packages that do the same job and could replace expressions.

  • cel

    Parses and evaluates Common Expression Language (CEL) expressions in Dart.

  • apollovm

    Portable multi-language VM to parse, run, translate, and compile Dart, Java, Kotlin, Go, C#, JS, and Python.

  • json_path

    Dart implementation of RFC 9535 JSONPath for querying and manipulating JSON

  • math_parser

    Parse and evaluate mathematical expressions in Dart.

Works with

Packages commonly used together with expressions: ones it builds on, ones built on it, and its own family.