findQuestionByRef static method

QuestionDef? findQuestionByRef(
  1. TreeReference ref,
  2. FormElement element
)

The question bound to ref under element (repeat-agnostic when element is the form).

Implementation

static QuestionDef? findQuestionByRef(
  TreeReference ref,
  FormElement element,
) {
  if (element is FormDef) ref = ref.genericize();
  if (element is QuestionDef) return ref == element.bind ? element : null;
  for (final child in element.children) {
    final found = findQuestionByRef(ref, child);
    if (found != null) return found;
  }
  return null;
}