stepBody method

Widget stepBody(
  1. String id,
  2. RPAnswerFormat answerFormat
)

Builds the step body widget based on the answer format of each step.

Implementation

Widget stepBody(String id, RPAnswerFormat answerFormat) {
  switch (answerFormat.runtimeType) {
    case const (RPIntegerAnswerFormat):
      return RPUIIntegerQuestionBody((answerFormat as RPIntegerAnswerFormat),
          (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);

        checkReadyToProceed();
      });
    case const (RPDoubleAnswerFormat):
      return RPUIDoubleQuestionBody((answerFormat as RPDoubleAnswerFormat),
          (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);

        checkReadyToProceed();
      });
    case const (RPChoiceAnswerFormat):
      return RPUIChoiceQuestionBody((answerFormat as RPChoiceAnswerFormat),
          (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);

        checkReadyToProceed();
      });
    case const (RPSliderAnswerFormat):
      return RPUISliderQuestionBody((answerFormat as RPSliderAnswerFormat),
          (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);

        checkReadyToProceed();
      });
    case const (RPImageChoiceAnswerFormat):
      return RPUIImageChoiceQuestionBody(
          (answerFormat as RPImageChoiceAnswerFormat), (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);

        checkReadyToProceed();
      });
    case const (RPDateTimeAnswerFormat):
      return RPUIDateTimeQuestionBody(
          (answerFormat as RPDateTimeAnswerFormat), (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);

        checkReadyToProceed();
      });
    case const (RPTextAnswerFormat):
      return RPUITextInputQuestionBody((answerFormat as RPTextAnswerFormat),
          (result) {
        RPStepResult tempResult = stepResult?.results[id] as RPStepResult;
        tempResult.questionTitle = widget.formStep.questions
            .where((step) => step.identifier == id)
            .first
            .title;
        tempResult.setResult(result);
        stepResult?.results[id] = tempResult;

        checkReadyToProceed();
      });
    default:
      return Container();
  }
}