fix: the quiz answering and add loading on the join quiz
This commit is contained in:
parent
1c6ce0d023
commit
b8c7d62c8c
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:quiz_app/app/routes/app_pages.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/controllers/user_controller.dart';
|
||||||
import 'package:quiz_app/data/dto/waiting_room_dto.dart';
|
import 'package:quiz_app/data/dto/waiting_room_dto.dart';
|
||||||
import 'package:quiz_app/data/models/quiz/quiz_info_model.dart';
|
import 'package:quiz_app/data/models/quiz/quiz_info_model.dart';
|
||||||
|
@ -29,11 +29,18 @@ class JoinRoomController extends GetxController {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
CustomFloatingLoading.showLoadingDialog(Get.context!);
|
||||||
_socketService.initSocketConnection();
|
_socketService.initSocketConnection();
|
||||||
|
|
||||||
_socketService.joinRoom(sessionCode: code, userId: _userController.userData!.id);
|
_socketService.joinRoom(sessionCode: code, userId: _userController.userData!.id);
|
||||||
_socketService.errors.listen((error) {
|
_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) {
|
_socketService.roomMessages.listen((data) {
|
||||||
|
@ -42,6 +49,7 @@ class JoinRoomController extends GetxController {
|
||||||
final Map<String, dynamic> sessionInfoJson = dataPayload["session_info"];
|
final Map<String, dynamic> sessionInfoJson = dataPayload["session_info"];
|
||||||
final Map<String, dynamic> quizInfoJson = dataPayload["quiz_info"];
|
final Map<String, dynamic> quizInfoJson = dataPayload["quiz_info"];
|
||||||
|
|
||||||
|
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||||
Get.toNamed(
|
Get.toNamed(
|
||||||
AppRoutes.waitRoomPage,
|
AppRoutes.waitRoomPage,
|
||||||
arguments: WaitingRoomDTO(
|
arguments: WaitingRoomDTO(
|
||||||
|
|
|
@ -190,27 +190,6 @@ class JoinRoomView extends GetView<JoinRoomController> {
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 30),
|
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,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -57,13 +57,11 @@ class PlayQuizMultiplayerController extends GetxController {
|
||||||
final model = MultiplayerQuestionModel.fromJson(Map<String, dynamic>.from(data));
|
final model = MultiplayerQuestionModel.fromJson(Map<String, dynamic>.from(data));
|
||||||
currentQuestion.value = model;
|
currentQuestion.value = model;
|
||||||
|
|
||||||
// Start the timer for this question
|
|
||||||
_startTimer(model.duration);
|
_startTimer(model.duration);
|
||||||
});
|
});
|
||||||
|
|
||||||
_socketService.quizDone.listen((_) {
|
_socketService.quizDone.listen((_) {
|
||||||
isDone.value = true;
|
isDone.value = true;
|
||||||
// Cancel timer when quiz is done
|
|
||||||
_cancelTimer();
|
_cancelTimer();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -98,8 +96,8 @@ class PlayQuizMultiplayerController extends GetxController {
|
||||||
_timer = null;
|
_timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void selectOptionAnswer(String option) {
|
void selectOptionAnswer(int choosenIndex) {
|
||||||
selectedAnswer.value = option;
|
selectedAnswer.value = choosenIndex.toString();
|
||||||
buttonType.value = ButtonType.primary;
|
buttonType.value = ButtonType.primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ class PlayQuizMultiplayerView extends GetView<PlayQuizMultiplayerController> {
|
||||||
return Column(
|
return Column(
|
||||||
children: List.generate(options!.length, (index) {
|
children: List.generate(options!.length, (index) {
|
||||||
final option = options[index];
|
final option = options[index];
|
||||||
final isSelected = controller.selectedAnswer.value == option;
|
final isSelected = controller.selectedAnswer.value == index.toString();
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
margin: const EdgeInsets.only(bottom: 12),
|
||||||
|
@ -173,7 +173,7 @@ class PlayQuizMultiplayerView extends GetView<PlayQuizMultiplayerController> {
|
||||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
),
|
),
|
||||||
onPressed: () => controller.selectOptionAnswer(option),
|
onPressed: () => controller.selectOptionAnswer(index),
|
||||||
child: Text(option),
|
child: Text(option),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue