fix: the quiz answering and add loading on the join quiz

This commit is contained in:
akhdanre 2025-05-18 22:12:23 +07:00
parent 1c6ce0d023
commit b8c7d62c8c
4 changed files with 14 additions and 29 deletions

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:quiz_app/app/routes/app_pages.dart';
import 'package:quiz_app/core/utils/logger.dart';
import 'package:quiz_app/core/utils/custom_floating_loading.dart';
import 'package:quiz_app/data/controllers/user_controller.dart';
import 'package:quiz_app/data/dto/waiting_room_dto.dart';
import 'package:quiz_app/data/models/quiz/quiz_info_model.dart';
@ -29,11 +29,18 @@ class JoinRoomController extends GetxController {
);
return;
}
CustomFloatingLoading.showLoadingDialog(Get.context!);
_socketService.initSocketConnection();
_socketService.joinRoom(sessionCode: code, userId: _userController.userData!.id);
_socketService.errors.listen((error) {
logC.i(error);
Get.snackbar(
"not found",
"Ruangan tidak ditemukan",
backgroundColor: Get.theme.colorScheme.error.withValues(alpha: 0.9),
colorText: Colors.white,
);
CustomFloatingLoading.hideLoadingDialog(Get.context!);
});
_socketService.roomMessages.listen((data) {
@ -42,6 +49,7 @@ class JoinRoomController extends GetxController {
final Map<String, dynamic> sessionInfoJson = dataPayload["session_info"];
final Map<String, dynamic> quizInfoJson = dataPayload["quiz_info"];
CustomFloatingLoading.hideLoadingDialog(Get.context!);
Get.toNamed(
AppRoutes.waitRoomPage,
arguments: WaitingRoomDTO(

View File

@ -190,27 +190,6 @@ class JoinRoomView extends GetView<JoinRoomController> {
),
const SizedBox(height: 30),
// TweenAnimationBuilder<double>(
// duration: const Duration(milliseconds: 800),
// tween: Tween(begin: 0.0, end: 1.0),
// builder: (context, value, child) {
// return Opacity(
// opacity: value,
// child: child,
// );
// },
// child: TextButton(
// onPressed: () {},
// child: Text(
// context.tr("create_new_room"),
// style: TextStyle(
// color: AppColors.primaryBlue,
// fontWeight: FontWeight.w500,
// ),
// ),
// ),
// ),
],
),
),

View File

@ -57,13 +57,11 @@ class PlayQuizMultiplayerController extends GetxController {
final model = MultiplayerQuestionModel.fromJson(Map<String, dynamic>.from(data));
currentQuestion.value = model;
// Start the timer for this question
_startTimer(model.duration);
});
_socketService.quizDone.listen((_) {
isDone.value = true;
// Cancel timer when quiz is done
_cancelTimer();
});
}
@ -98,8 +96,8 @@ class PlayQuizMultiplayerController extends GetxController {
_timer = null;
}
void selectOptionAnswer(String option) {
selectedAnswer.value = option;
void selectOptionAnswer(int choosenIndex) {
selectedAnswer.value = choosenIndex.toString();
buttonType.value = ButtonType.primary;
}

View File

@ -160,7 +160,7 @@ class PlayQuizMultiplayerView extends GetView<PlayQuizMultiplayerController> {
return Column(
children: List.generate(options!.length, (index) {
final option = options[index];
final isSelected = controller.selectedAnswer.value == option;
final isSelected = controller.selectedAnswer.value == index.toString();
return Container(
margin: const EdgeInsets.only(bottom: 12),
@ -173,7 +173,7 @@ class PlayQuizMultiplayerView extends GetView<PlayQuizMultiplayerController> {
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
onPressed: () => controller.selectOptionAnswer(option),
onPressed: () => controller.selectOptionAnswer(index),
child: Text(option),
),
);