diff --git a/lib/component/notification/pop_up_confirmation.dart b/lib/component/notification/pop_up_confirmation.dart new file mode 100644 index 0000000..c069e63 --- /dev/null +++ b/lib/component/notification/pop_up_confirmation.dart @@ -0,0 +1,84 @@ +import 'package:flutter/material.dart'; +import 'package:quiz_app/app/const/colors/app_colors.dart'; + +class AppDialog { + static Future showExitConfirmationDialog(BuildContext context) async { + await showDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return Dialog( + backgroundColor: AppColors.background, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + child: Padding( + padding: const EdgeInsets.all(20), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Text( + "Keluar tanpa menyimpan?", + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: AppColors.darkText, + ), + textAlign: TextAlign.center, + ), + const SizedBox(height: 16), + const Text( + "Perubahan yang belum disimpan akan hilang. Anda yakin ingin keluar?", + style: TextStyle( + fontSize: 14, + color: AppColors.softGrayText, + ), + textAlign: TextAlign.center, + ), + const SizedBox(height: 24), + Row( + children: [ + Expanded( + child: ElevatedButton( + onPressed: () => Navigator.pop(context), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + foregroundColor: AppColors.primaryBlue, + side: const BorderSide(color: AppColors.primaryBlue), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + padding: const EdgeInsets.symmetric(vertical: 14), + ), + child: const Text("Batal"), + ), + ), + const SizedBox(width: 12), + Expanded( + child: ElevatedButton( + onPressed: () { + Navigator.pop(context); // Tutup dialog + Navigator.pop(context); // Kembali halaman + }, + style: ElevatedButton.styleFrom( + backgroundColor: AppColors.primaryBlue, + foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + padding: const EdgeInsets.symmetric(vertical: 14), + ), + child: const Text("Keluar"), + ), + ), + ], + ) + ], + ), + ), + ); + }, + ); + } +} diff --git a/lib/feature/quiz_creation/controller/quiz_creation_controller.dart b/lib/feature/quiz_creation/controller/quiz_creation_controller.dart index 53be6a7..041912a 100644 --- a/lib/feature/quiz_creation/controller/quiz_creation_controller.dart +++ b/lib/feature/quiz_creation/controller/quiz_creation_controller.dart @@ -1,7 +1,9 @@ +import 'package:flutter/material.dart'; import 'package:flutter/widgets.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/component/notification/pop_up_confirmation.dart'; import 'package:quiz_app/data/models/quiz/quiestion_data_model.dart'; class QuizCreationController extends GetxController { @@ -132,4 +134,12 @@ class QuizCreationController extends GetxController { void onDone() { Get.toNamed(AppRoutes.quizPreviewPage, arguments: quizData); } + + void onBack(BuildContext context) { + if (quizData.length <= 1) { + Navigator.pop(context); + } else { + AppDialog.showExitConfirmationDialog(context); + } + } } diff --git a/lib/feature/quiz_creation/view/quiz_creation_view.dart b/lib/feature/quiz_creation/view/quiz_creation_view.dart index 1ef3a01..f99f694 100644 --- a/lib/feature/quiz_creation/view/quiz_creation_view.dart +++ b/lib/feature/quiz_creation/view/quiz_creation_view.dart @@ -25,7 +25,7 @@ class QuizCreationView extends GetView { ), leading: IconButton( icon: const Icon(Icons.arrow_back_ios_new_rounded, color: AppColors.darkText), - onPressed: () => Navigator.pop(context), + onPressed: () => controller.onBack(context), ), centerTitle: true, ),