Skip to content

Commit

Permalink
Fix counter error with save&next, previous, add dartdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
SriramPatibanda authored and nayakastha committed Aug 11, 2021
1 parent 918de12 commit 0a8e908
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
8 changes: 7 additions & 1 deletion aptiche/lib/views/quiz/quiz_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ class QuizController extends GetxController {
questions[questionIndex.value].options[radioGroupValue.value.index];
questionIndex.value++;
// The radio group value has to be set to NON for the next question.
radioGroupValue.value = ChoicesEnum.NON;
if (questions[questionIndex.value].choice == null) {
radioGroupValue.value = ChoicesEnum.NON;
}
print(questionIndex.value);
}

/// A function when triggered shows the previous question in the quiz.
void previous() {
questions[questionIndex.value].choice =
questions[questionIndex.value].options[radioGroupValue.value.index];
questionIndex.value--;
print(questionIndex.value);
}

/// A function that calculates the total score of the user.
Expand Down
50 changes: 26 additions & 24 deletions aptiche/lib/views/quiz/quiz_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,32 @@ class QuizView extends GetView<QuizController> {
height: SizeConfig.screenHeight! * 0.075,
alignment: Alignment.bottomCenter,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
if (controller.questionIndex.value > 0)
CustomButton(
horizontalPadding: 7,
verticalPadding: 2,
text: 'Previous',
onTap: () {
controller.previous();
},
),
if (controller.questionIndex.value + 1 <
controller.questions.length)
CustomButton(
horizontalPadding: 7,
verticalPadding: 2,
text: 'Save & Next',
onTap: () {
controller.saveAndNext();
},
),
],
child: Obx(
() => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
if (controller.questionIndex.value > 0)
CustomButton(
horizontalPadding: SizeConfig.safeBlockHorizontal! * 1.6,
verticalPadding: SizeConfig.safeBlockVertical! * 0.27,
text: 'Previous',
onTap: () {
controller.previous();
},
),
if (controller.questionIndex.value + 1 <
controller.questions.length)
CustomButton(
horizontalPadding: SizeConfig.safeBlockHorizontal! * 1.6,
verticalPadding: SizeConfig.safeBlockVertical! * 0.27,
text: 'Save & Next',
onTap: () {
controller.saveAndNext();
},
),
],
),
),
),
body: SafeArea(
Expand Down
1 change: 1 addition & 0 deletions aptiche/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
url_launcher: ^6.0.7
graphql_flutter: ^5.0.0
intl: ^0.17.0
dartdoc: ^1.0.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 0a8e908

Please sign in to comment.