Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added previous button in QuizView and toggleable radio #71

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions aptiche/lib/views/quiz/quiz_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class QuizController extends GetxController {
///Stores the user score of the quiz
Rx<int> userScore = 0.obs;

///[questionIndex] stream subscription
StreamSubscription<int>? _questionIndexStream;
ayyysh04 marked this conversation as resolved.
Show resolved Hide resolved
// Functions

/// A void function which controls the behaviour of the timer(`timeout`)
Expand All @@ -61,15 +63,28 @@ class QuizController extends GetxController {
});
}

@override
void onInit() {
_questionIndexStream = questionIndex.listen((_) {
update();
});
super.onInit();
}

@override
void dispose() {
_questionIndexStream?.cancel();
timer.cancel();
super.dispose();
}

/// Changes [radioGroupValue] to the selected option.
void selectOption(ChoicesEnum newValue) {
radioGroupValue.value = newValue;
void selectOption(ChoicesEnum? newValue) {
if (newValue == null) {
radioGroupValue.value = ChoicesEnum.NON;
} else
radioGroupValue.value = newValue;
update();
}

/// Checks whether the question is answered or not
Expand Down
24 changes: 12 additions & 12 deletions aptiche/lib/views/quiz/quiz_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ class QuizView extends GetView<QuizController> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
/* if (controller.questionIndex.value > 0)
if (controller.questionIndex.value > 0)
CustomButton(
horizontalPadding: SizeConfig.safeBlockHorizontal! * 1.4,
verticalPadding: SizeConfig.safeBlockVertical! * 0.27,
text: 'Previous',
onTap: () {
print(controller.radioGroupValue.value);
//controller.previous();
// print(controller.radioGroupValue.value);
controller.previous();
},
), */
CustomButton(
horizontalPadding: SizeConfig.safeBlockHorizontal! * 1.4,
verticalPadding: SizeConfig.safeBlockVertical! * 0.27,
text: 'Clear Choice',
onTap: () {
controller.clearRadioGroup();
},
),
),
// CustomButton(
// horizontalPadding: SizeConfig.safeBlockHorizontal! * 1.4,
// verticalPadding: SizeConfig.safeBlockVertical! * 0.27,
// text: 'Clear Choice',
ayyysh04 marked this conversation as resolved.
Show resolved Hide resolved
// onTap: () {
// controller.clearRadioGroup();
ayyysh04 marked this conversation as resolved.
Show resolved Hide resolved
// },
// ),
if (controller.questionIndex.value + 1 <
controller.questions.length)
CustomButton(
Expand Down
30 changes: 17 additions & 13 deletions aptiche/lib/widgets/quiz/choices_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import 'package:aptiche/utils/ui_scaling.dart';
import 'package:aptiche/views/quiz/quiz_controller.dart';
import 'package:aptiche/widgets/quiz/custom_radio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

class ChoicesListView extends GetView<QuizController> {
class ChoicesListView extends StatelessWidget {
const ChoicesListView({
Key? key,
}) : super(key: key);
Expand All @@ -17,18 +18,21 @@ class ChoicesListView extends GetView<QuizController> {
4,
(int index) => Column(
children: <Widget>[
Obx(
() => CustomRadio(
label: controller
.questions[controller.questionIndex.value].options[index],
padding: EdgeInsets.zero,
groupValue: controller.radioGroupValue.value,
value: ChoicesEnum.values[index],
onChanged: (ChoicesEnum newValue) {
controller.selectOption(newValue);
},
),
),
GetBuilder<QuizController>(
init: Get.find<QuizController>(),
builder: (QuizController controller) {
return CustomRadio(
label: controller.questions[controller.questionIndex.value]
.options[index],
padding: EdgeInsets.zero,
groupValue: controller.radioGroupValue.value,
value: ChoicesEnum.values[index],
onChanged: (ChoicesEnum? newValue) {
controller.selectOption(newValue);
},
toggleable: true,
);
}),
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal! * 6,
Expand Down
7 changes: 5 additions & 2 deletions aptiche/lib/widgets/quiz/custom_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class CustomRadio extends StatelessWidget {
required this.groupValue,
required this.value,
required this.onChanged,
this.toggleable = false,
}) : super(key: key);

final bool toggleable;
final String label;
final EdgeInsets padding;
final ChoicesEnum groupValue;
Expand All @@ -23,7 +24,8 @@ class CustomRadio extends StatelessWidget {
onTap: () {
if (value != groupValue) {
onChanged(value);
}
} else
onChanged(null);
},
child: Padding(
padding: padding,
Expand All @@ -35,6 +37,7 @@ class CustomRadio extends StatelessWidget {
Theme.of(context).primaryColor),
groupValue: groupValue,
value: value,
toggleable: toggleable,
onChanged: (ChoicesEnum? newValue) {
onChanged(newValue);
},
Expand Down