readsParentSize function

bool readsParentSize(
  1. BaseNode node
)

Whether node reads the parent variable in a binding, a formula or an inline ${...} text, so it is built inside a ParentSizeScope.

Implementation

bool readsParentSize(BaseNode node) {
  if (hasFractionalSize(node)) return true;
  bool isParent(String path) =>
      VariableMatch.parse(path.wrapWithVariableSyntax())?.name == 'parent';
  for (final String path in node.variables.values) {
    final String? expression = FormulaEvaluator.exactExpression(path);
    if (expression != null) {
      if (FormulaEvaluator.referencedPaths(expression).any(isParent)) {
        return true;
      }
    } else if (isParent(path)) {
      return true;
    }
  }
  for (final List<String> paths in node.multipleVariables.values) {
    if (paths.any(isParent)) return true;
  }
  for (final String template in inlineTextTemplatesOf(node)) {
    if (FormulaEvaluator.referencedPathsInText(template).any(isParent)) {
      return true;
    }
    for (final RegExpMatch match in variablePathRegex.allMatches(template)) {
      final String? path = match.namedGroup('value');
      if (path != null && isParent(path)) return true;
    }
  }
  return false;
}