Expression constructor
Expression({})
Create a new math expression for example:
final expression = Expression(
expression: "a / b",
variables: { "a": 4, "b": 2 }
);
print("${expression.value}"); // -> 4 / 2 = 2
// Call clear to free up memory
expression.clear();
Implementation
Expression(
{required String expression,
required Map<String, double> variables,
Map<String, double>? constants})
: this._stringCache = variables,
this._constants = constants,
super(
expression: expression,
variables: variables,
constants: constants) {
init();
// Cache variable names, because toNativeUtf8 is slow
_variableNames = variables.map((name, value) =>
MapEntry(name, FlutterExprtkPlatform.instance.toNativeUtf8(name)));
_pExpression = FlutterExprtkPlatform.instance.newExpression(
expression: expression, variables: _stringCache, constants: _constants);
if (FlutterExprtkPlatform.instance.isValid(_pExpression) == 0) {
clear();
throw InvalidExpressionException();
}
}