Implement the MultiChoicesQuestion model extending Question. It should be implemented using freezed
MultiChoicesQuestion schema
**Note**: the schema is represented using OpenAPI spec for simplicity.
```yaml
MultipleChoiceQuestion:
description: Representation of a multiple-choice question
allOf:
- $ref: "#/components/schemas/Question"
- properties:
rightAnswerIndex:
description: Indicate the answer index in the options
options:
type: array
minimum: 2
maximum: 4
items:
$ref: "#/components/schemas/MultiChoiceOption"
required:
- rightAnswerIndex
- options
```
Implement a MultiChoicesQuestionViewModel that:
extends QuestionViewModel
implement a method to validate the response
What needs to be done
Implement the MultiChoicesQuestion model extending Question (format: multiple_choice) under src/practice/questions/models using freezed (documentation)
Implement a MultiChoicesQuestionViewModel view-model, under src/practice/questions:
extends QuestionViewModel
constructor takes:
MultiChoiceQuestion question
everything from QuestionViewModel constructor
have a int _selectedOptionIndex = -1
have a getter MultiChoiceOption? selectedOption that give the current selected option based on _selectedOptionIndex
implement a onOptionPressed(int index) that can update the currently selected option
Requirements
Implement the
MultiChoicesQuestion
model extendingQuestion
. It should be implemented using freezed
**Note**: the schema is represented using OpenAPI spec for simplicity. ```yaml MultipleChoiceQuestion: description: Representation of a multiple-choice question allOf: - $ref: "#/components/schemas/Question" - properties: rightAnswerIndex: description: Indicate the answer index in the options options: type: array minimum: 2 maximum: 4 items: $ref: "#/components/schemas/MultiChoiceOption" required: - rightAnswerIndex - options ```MultiChoicesQuestion
schemaImplement a
MultiChoicesQuestionViewModel
that:QuestionViewModel
What needs to be done
MultiChoicesQuestion
model extendingQuestion
(format:multiple_choice
) undersrc/practice/questions/models
using freezed (documentation)MultiChoicesQuestionViewModel
view-model, undersrc/practice/questions
:QuestionViewModel
MultiChoiceQuestion question
QuestionViewModel
constructorint _selectedOptionIndex = -1
MultiChoiceOption? selectedOption
that give the current selected option based on_selectedOptionIndex
onOptionPressed(int index)
that can update the currently selected optiononSubmitPressed
method, it should:_selectedOptionIndex
is -1, stop here_selectedOptionIndex == question.rightAnswerIndex
:_onSuccess(explanation: question.explanation)
question.knowledgeUpdates[0].grade
by 1_onError(_determineAskAgain(), explanation: question.explanation)
provide the explanation only if knowledge update is 1 or lessDependencies
Child of #168
Depends on:
171
173
Dev notes