MathExpression class
Represents a single math expression with its various forms.
Uses a native expression parser for evaluation, enabling Flutter rendering without WebView/JSXGraph dependencies.
For explicit functions (e.g. "x^2", "sin(x)"), evaluator is a
double Function(double) and samplePoints samples y = f(x).
For implicit equations (e.g. "x^2+y^2=1"), implicitEvaluator is a
double Function(double, double) and sampleContour finds the zero set.
Constructors
-
MathExpression.fromInput(String input, {Map<
String, double> parameterValues = const {}}) -
Create a MathExpression from user input.
factory
Properties
- evaluator → double Function(double)
-
For explicit functions: evaluates at a given x value.
For implicit equations: evaluates f(x, y) at a given x (y defaults to 0).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- implicitEvaluator → double Function(double, double)?
-
For implicit equations: evaluates f(x, y). Null for explicit.
final
- isValid → bool
-
Whether this expression is valid (non-empty and parseable).
no setter
- latexDisplay → String
-
LaTeX display string for rendering.
final
- normalizedExpression → String
-
The normalized expression ready for numeric parsing.
final
-
parameters
→ Set<
String> -
Set of parameter names extracted from the expression (e.g. {"a", "b"}).
final
- parseError → String?
-
The error message if the expression is invalid.
no setter
- rawExpression → String
-
The raw expression as entered by the user (e.g. "x^2", "x=1").
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → MathExpressionType
-
The type of expression (explicit or implicit).
final
Methods
-
immutableCopy(
) → MathExpression - Copy this expression with an unmodifiable parameter-name set.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sampleContourSegments(
{double xMin = -10, double xMax = 10, double yMin = -10, double yMax = 10, int gridX = 80, int gridY = 80}) → List< List< Map< >String, double> > - Sample the contour of an implicit equation f(x,y)=0 within the viewport.
-
samplePoints(
{double xMin = -10, double xMax = 10, int numPoints = 200}) → List< Map< String, double> > -
Sample the function at
numPointspoints withinxMin..xMax. -
samplePointSegments(
{double xMin = -10, double xMax = 10, int numPoints = 200}) → List< List< Map< >String, double> > -
Sample the function into contiguous finite runs within
xMin..xMax. Invalid samples split runs so graph renderers do not join across discontinuities such as vertical asymptotes. -
toString(
) → String -
A string representation of this object.
inherited
-
withParameters(
Map< String, double> parameterValues) → MathExpression - Create an updated evaluator with new parameter values.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
generateFunctionBody(
String jsExpression) → String - Generate a JavaScript function body from a JS expression.
-
toJsExpression(
String input) → String - Convert a normalized expression to a JavaScript-evaluable form.