Skip to content

Commit

Permalink
Merge pull request #89 from ia-toki/update/quiz-exercise-type
Browse files Browse the repository at this point in the history
Update/quiz exercise type
  • Loading branch information
DandiIndraWijaya authored Nov 15, 2023
2 parents 4987a88 + fc67214 commit e520701
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
currentProblem =
await quizExerciseRepository.getQuizExercise(problemIdList.first);

currentProblem.question.options?.shuffle();

final duration = quiz.duration_minute[participation.challenge_group];
if (duration == null) {
throw Exception('Duration for selected Challenge Group not found');
Expand Down Expand Up @@ -153,7 +155,9 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
}

Future<void> submitAnswer() async {
if ((currentProblem.type == 'MULTIPLE_CHOICE' && selectedAnswer == '') ||
if (((currentProblem.type == 'MULTIPLE_CHOICE' ||
currentProblem.type == 'MULTIPLE_CHOICE_IMAGE') &&
selectedAnswer == '') ||
(currentProblem.type == 'SHORT_ANSWER') && shortAnswer == '') {
emit(
QuizExerciseShow(
Expand All @@ -162,18 +166,19 @@ class QuizExerciseCubit extends Cubit<QuizExerciseState> {
remainingDuration: Duration(seconds: remainingDuration),
selectedAnswer: selectedAnswer,
shortAnswer: shortAnswer,
modalErrorMessage: currentProblem.type == 'MULTIPLE_CHOICE'
? 'Pilih salah satu jawaban'
: 'Isi jawaban anda',
modalErrorMessage: currentProblem.type == 'SHORT_ANSWER'
? 'Isi jawaban anda'
: 'Pilih salah satu jawaban',
),
);
return;
}
try {
var verdict = 'INCORRECT';

if (currentProblem.type == 'MULTIPLE_CHOICE' &&
currentProblem.answer.correctAnswer.contains(selectedAnswer)) {
if (currentProblem.type == 'MULTIPLE_CHOICE' ||
currentProblem.type == 'MULTIPLE_CHOICE_IMAGE' &&
currentProblem.answer.correctAnswer.contains(selectedAnswer)) {
verdict = 'CORRECT';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class _QuizExercisePageState extends State<QuizExercisePage> {
return state is QuizExerciseShow;
}, builder: (context, state) {
if (state is QuizExerciseShow) {
// Shuffle Quiz Options
state.quizExercise.question.options?.shuffle();
var index = 0;

return Scaffold(
backgroundColor: Colors.transparent,
body: AlertDialog(
Expand All @@ -192,16 +192,40 @@ class _QuizExercisePageState extends State<QuizExercisePage> {
Html(data: state.quizExercise.question.content),
),
),
...state.quizExercise.question.options!
.map((e) => RadioListTile(
title: Text(e.content),
value: e.id,
groupValue: state.selectedAnswer,
onChanged: (value) {
context
.read<QuizExerciseCubit>()
.selectAnswer(e.id);
})),
...state.quizExercise.question.options!.map((e) {
final current = String.fromCharCode(65 + index);
index++;

return RadioListTile(
title: SizedBox(
width: 100,
child: Row(
children: [
Text(
current,
style: const TextStyle(fontSize: 12),
),
const SizedBox(
width: 10,
),
state.quizExercise.type ==
'MULTIPLE_CHOICE_IMAGE'
? Image.network(
e.content,
width: 140,
)
: Text(e.content),
],
),
),
value: e.id,
groupValue: state.selectedAnswer,
onChanged: (value) {
context
.read<QuizExerciseCubit>()
.selectAnswer(e.id);
});
}),
state.quizExercise.type == 'SHORT_ANSWER'
? Container(
padding: const EdgeInsets.only(top: 20),
Expand Down Expand Up @@ -236,7 +260,6 @@ class _QuizExercisePageState extends State<QuizExercisePage> {
text: 'OK',
onTap: () {
var error = '';

if (state.quizExercise.type == 'SHORT_ANSWER') {
if (state.shortAnswer == '') {
error = 'Isi jawaban anda';
Expand Down

0 comments on commit e520701

Please sign in to comment.