Skip to content

Commit

Permalink
update answer input
Browse files Browse the repository at this point in the history
  • Loading branch information
DandiIndraWijaya committed Nov 10, 2023
1 parent a311d83 commit 5aaeb2f
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class QuizExerciseShow extends QuizExerciseState {
quizExercise,
remainingDuration,
selectedAnswer,
shortAnswer,
modalErrorMessage,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,75 +163,110 @@ class _QuizExercisePageState extends State<QuizExercisePage> {
return state is QuizExerciseShow;
}, builder: (context, state) {
if (state is QuizExerciseShow) {
return AlertDialog(
content: SingleChildScrollView(
child: Column(
children: [
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text(
'Pertanyaan',
style: FontTheme.blackTextBold(),
return Scaffold(
backgroundColor: Colors.transparent,
body: AlertDialog(
content: SingleChildScrollView(
child: Column(
children: [
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text(
'Pertanyaan',
style: FontTheme.blackTextBold(),
),
),
),
SizedBox(
width: 400,
height: 200,
child: SingleChildScrollView(
child:
Html(data: state.quizExercise.question.content),
SizedBox(
width: 400,
height: 200,
child: SingleChildScrollView(
child:
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.type == 'SHORT_ANSWER'
? Container(
padding: const EdgeInsets.only(top: 20),
child: CustomTextField('Jawaban anda', (value) {
context
.read<QuizExerciseCubit>()
.fillAnswer(value);
}, (p0) => null, ''),
)
: Container(),
Text(state.modalErrorMessage),
],
),
),
actions: [
SizedBox(
width: 100,
height: 50,
child: Button(
buttonType: ButtonType.secondary,
text: 'Cancel',
onTap: () {
Navigator.pop(context);
},
...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.type == 'SHORT_ANSWER'
? Container(
padding: const EdgeInsets.only(top: 20),
child: CustomTextField('Jawaban anda', (value) {
context
.read<QuizExerciseCubit>()
.fillAnswer(value);
}, (p0) => null, ''),
)
: Container(),
Text(state.modalErrorMessage),
],
),
),
SizedBox(
width: 100,
height: 50,
child: Button(
buttonType: ButtonType.tertiary,
text: 'OK',
onTap: () {
context.read<QuizExerciseCubit>().submitAnswer();
Navigator.pop(context);
},
actions: [
SizedBox(
width: 100,
height: 50,
child: Button(
buttonType: ButtonType.secondary,
text: 'Cancel',
onTap: () {
Navigator.pop(context);
},
),
),
),
],
SizedBox(
width: 100,
height: 50,
child: Button(
buttonType: ButtonType.tertiary,
text: 'OK',
onTap: () {
var error = '';

if (state.quizExercise.type == 'SHORT_ANSWER') {
if (state.shortAnswer == '') {
error = 'Isi jawaban anda';
}
} else {
if (state.selectedAnswer == '') {
error = 'Pilih salah satu jawaban';
}
}

if (error != '') {
final snackBar = SnackBar(
backgroundColor: Colors.red,
duration: const Duration(seconds: 1),
behavior: SnackBarBehavior.floating,
margin: EdgeInsets.only(
bottom:
MediaQuery.of(context).size.height - 150,
left: 10,
right: 10),
content: Text(error),
);

ScaffoldMessenger.of(context)
.showSnackBar(snackBar);

error = '';
return;
}

context.read<QuizExerciseCubit>().submitAnswer();
Navigator.pop(context);
},
),
),
],
),
);
}
return const SizedBox(
Expand Down

0 comments on commit 5aaeb2f

Please sign in to comment.