validate method

bool validate()

This function is used to validate the question cards.

Instances of PolarQuestion and NestedQuestion that have the isMandatory flag set will be checked if they are equal to null or not. Instances of Question having the validate property set to a function will execute that function.

Implementation

bool validate() {
  int count = 0;

  expanded.forEach((element) {
    if (!((element.keys.toList()[0]) is NestedQuestion ||
            (element.keys.toList()[0]) is PolarQuestion) &&
        (element.keys.toList()[0].validate != null &&
            element.keys
                    .toList()[0]
                    .validate(element.keys.toList()[0].answer.text) !=
                null)) {
      count++;
      element.keys.toList()[0].errorMessage = element.keys
          .toList()[0]
          .validate(element.keys.toList()[0].answer.text);
      element.keys.toList()[0].hasError = true;
    }

    if (!((element.keys.toList()[0]) is NestedQuestion ||
            (element.keys.toList()[0]) is PolarQuestion) &&
        (element.keys.toList()[0].validate != null &&
            element.keys
                    .toList()[0]
                    .validate(element.keys.toList()[0].answer.text) ==
                null)) {
      element.keys.toList()[0].errorMessage = null;
      element.keys.toList()[0].hasError = false;
    }

    if (element[element.keys.toList()[0]] == null &&
        element.keys.toList()[0] is PolarQuestion &&
        (element.keys.toList()[0] as PolarQuestion).isMandatory) {
      count++;
      if (element.keys.toList()[0] is PolarQuestion)
        (element.keys.toList()[0] as PolarQuestion).hasError = true;
    }
  });
  print("count:$count");
  callback();
  if (count > 0)
    return false;
  else
    return true;
}