nextStep method

void nextStep(
  1. FormStep? currentStep
)

Implementation

void nextStep(FormStep? currentStep) {
  FormStep? nextStep;
  if (currentStep?.relevantConditions == null) {
    nextStep = currentStep?.next;
  } else {
    String? formName;
    for (RelevantCondition element in currentStep!.relevantConditions!) {
      if (element.isValid(currentStep.result)) {
        nextStep = steps.firstWhereOrNull(
            (e) => (e.id?.id ?? "") == element.identifier.id);
        formName = element.formName;
        break;
      }
    }
    if (nextStep != null) {
      relevantStack.putIfAbsent((nextStep.id?.id ?? ""), () => currentStep);
    } else if (formName?.isNotEmpty ?? false) {
      FormStackForm? nextFormSatck = FormStack.formByInstaceAndName(
          name: fromInstanceName, formName: formName!);
      if (nextFormSatck != null) {
        nextFormSatck.previousFormStackForm = this;
        onRenderFormSatackForm?.call(nextFormSatck);
        return;
      } else {
        nextStep = currentStep.next;
        nextStep?.previousStep = currentStep;
      }
    } else {
      nextStep = currentStep.next;
      nextStep?.previousStep = currentStep;
      if (nextStep == null) {
        onFinish?.call(result);
        clearResult();
      }
    }
  }

  if (nextStep != null) {
    onUpdate?.call(nextStep);
  } else {
    onUpdate?.call(steps.first);
    onFinish?.call(result);
    clearResult();
  }
}