feat: adding limit in the request with loading not dissmisable
This commit is contained in:
parent
dda268d2d5
commit
b575f75f6d
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<QuestionData> data;
|
||||
|
||||
RxList<SubjectModel> subjects = <SubjectModel>[].obs;
|
||||
|
@ -62,26 +65,31 @@ class QuizPreviewController extends GetxController {
|
|||
}
|
||||
|
||||
Future<void> 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!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue