diff --git a/lib/core/utils/custom_floating_loading.dart b/lib/core/utils/custom_floating_loading.dart new file mode 100644 index 0000000..2ac487d --- /dev/null +++ b/lib/core/utils/custom_floating_loading.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class CustomFloatingLoading { + static void showLoadingDialog(BuildContext context) { + showDialog( + context: context, + barrierDismissible: false, + barrierColor: Colors.black.withValues(alpha: 0.3), + builder: (BuildContext context) { + return PopScope( + canPop: false, + child: const Center( + child: CircularProgressIndicator(), + ), + ); + }, + ); + } + + static void hideLoadingDialog(BuildContext context) { + Navigator.of(context).pop(); + } +} diff --git a/lib/feature/quiz_preview/controller/quiz_preview_controller.dart b/lib/feature/quiz_preview/controller/quiz_preview_controller.dart index c555aef..e9dad1b 100644 --- a/lib/feature/quiz_preview/controller/quiz_preview_controller.dart +++ b/lib/feature/quiz_preview/controller/quiz_preview_controller.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:quiz_app/app/const/enums/question_type.dart'; import 'package:quiz_app/app/routes/app_pages.dart'; +import 'package:quiz_app/core/utils/custom_floating_loading.dart'; import 'package:quiz_app/core/utils/custom_notification.dart'; import 'package:quiz_app/core/utils/logger.dart'; import 'package:quiz_app/data/controllers/user_controller.dart'; @@ -29,6 +30,8 @@ class QuizPreviewController extends GetxController { RxBool isPublic = false.obs; + RxBool isLoading = false.obs; + late final List data; RxList subjects = [].obs; @@ -62,26 +65,31 @@ class QuizPreviewController extends GetxController { } Future onSaveQuiz() async { - final title = titleController.text.trim(); - final description = descriptionController.text.trim(); - - if (title.isEmpty || description.isEmpty) { - CustomNotification.error( - title: 'Error', - message: 'Judul dan deskripsi tidak boleh kosong!', - ); - return; - } - - if (data.length < 10) { - CustomNotification.error( - title: 'Error', - message: 'Jumlah soal harus 10 atau lebih', - ); - return; - } - try { + if (isLoading.value) return; + + final title = titleController.text.trim(); + final description = descriptionController.text.trim(); + + if (title.isEmpty || description.isEmpty) { + CustomNotification.error( + title: 'Error', + message: 'Judul dan deskripsi tidak boleh kosong!', + ); + return; + } + + if (data.length < 10) { + CustomNotification.error( + title: 'Error', + message: 'Jumlah soal harus 10 atau lebih', + ); + return; + } + + isLoading.value = true; + CustomFloatingLoading.showLoadingDialog(Get.context!); + final now = DateTime.now(); final String formattedDate = "${now.day.toString().padLeft(2, '0')}-${now.month.toString().padLeft(2, '0')}-${now.year}"; @@ -108,6 +116,9 @@ class QuizPreviewController extends GetxController { } } catch (e) { logC.e(e); + } finally { + isLoading.value = false; + CustomFloatingLoading.hideLoadingDialog(Get.context!); } }