tryParse static method
Implementation
static CSSCalcValue? tryParse(RenderStyle renderStyle, String propertyName, String propertyValue) {
// calc()
if (CSSFunction.isFunction(propertyValue, functionName: CALC)) {
final List<CSSFunctionalNotation> fns = CSSFunction.parseFunction(propertyValue);
if (fns.isNotEmpty && fns.first.args.isNotEmpty) {
assert(fns.first.args.length == 1, 'Calc parameters count must be = 1');
final expression = fns.first.args.first;
final _CSSCalcParser parser = _CSSCalcParser(propertyName, renderStyle, expression);
final CalcExpressionNode? node = parser.processCalcExpression();
return CSSCalcValue(node);
}
}
// clamp(min, preferred, max)
if (CSSFunction.isFunction(propertyValue, functionName: 'clamp')) {
final List<CSSFunctionalNotation> fns = CSSFunction.parseFunction(propertyValue);
if (fns.isNotEmpty) {
final CSSFunctionalNotation fn = fns.first;
// Gracefully ignore invalid arity; leave parsing to other paths.
if (fn.args.length == 3) {
final CSSLengthValue minV = CSSLength.parseLength(fn.args[0].trim(), renderStyle, '${propertyName}_min');
final CSSLengthValue prefV = CSSLength.parseLength(fn.args[1].trim(), renderStyle, '${propertyName}_pref');
final CSSLengthValue maxV = CSSLength.parseLength(fn.args[2].trim(), renderStyle, '${propertyName}_max');
return CSSCalcValue(_ClampExpressionNode(minV, prefV, maxV));
}
}
}
return null;
}