evaluateDependencies method

void evaluateDependencies(
  1. Map<String, dynamic> currentAnswers
)

Implementation

void evaluateDependencies(Map<String, dynamic> currentAnswers) {
  // If there are no dependencies, retain the default states.
  if (dependencies == null) {
    return;
  }

  // generate visibility based on dependencies, if there
  if (dependencies!.isVisible != null) {
    String dependentQuestionId = dependencies!.isVisible!.onFId;
    var requiredValue = dependencies!.isVisible!.value;
    String answer =
        currentAnswers[dependentQuestionId]?.toString().toLowerCase() ?? '';
    isVisible = (answer == requiredValue);
  }

  // generate required status based on dependencies, if there
  if (dependencies!.isRequired != null) {
    String dependentQuestionId = dependencies!.isRequired!.onFId;
    var requiredValue = dependencies!.isRequired!.value;
    String answer =
        currentAnswers[dependentQuestionId]?.toString().toLowerCase() ?? '';
    isRequired = (answer == requiredValue);
  }
}