Skip to content
pubscout

math_parser

1.5.2, released 2 years ago by sominemo.com

Parse and evaluate mathematical expressions in Dart.

WASM-ready
$ flutter pub add math_parser
Source repository

What it does

Provides a parser that converts math strings into a tree of nodes and can calculate results with custom variables and functions. Supports equations, definite integrals, and custom function definitions.

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

Use it when

  • You need to evaluate user‑provided formulas at runtime
  • You require custom variables or functions in calculations
  • You want a pure‑Dart solution without native dependencies

Skip it when

  • Performance‑critical numeric computing where a compiled library is needed
  • Complex symbolic algebra or calculus beyond definite integrals

Strengths

  • No external native dependencies, works on all Flutter platforms
  • Supports custom variables, functions, and definite integrals
  • Clear API with documented node tree

Weaknesses

  • Limited to simple math; no symbolic manipulation or advanced calculus
  • Parsing errors can be verbose and may require manual handling

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:math_parser/math_parser.dart';

void main() {
  final expr = MathNodeExpression.fromString('(2*x)^(e^3 + 4) + y',
    variableNames: {'x','y'},
  );
  final result = expr.calc(MathVariableValues({'x':20,'y':10}));
  print(result);
}

Alternatives

Packages that do the same job and could replace math_parser.

  • petitparser

    A flexible parser combinator library that can be used to build custom math parsers with more control