Compare commits
10 Commits
655103247e
...
0a138793ae
Author | SHA1 | Date |
---|---|---|
|
0a138793ae | |
|
576f5b27ea | |
|
17cee7b7d7 | |
|
3cce4faadd | |
|
ae49bb34d0 | |
|
d5de5fb712 | |
|
ede385041e | |
|
b77229c26a | |
|
0283806cf3 | |
|
a7f5f98cf5 |
|
@ -38,8 +38,8 @@
|
|||
"library_title": "Quiz Library",
|
||||
"library_description": "A collection of quiz questions created for study.",
|
||||
"no_quiz_available": "No quizzes available yet.",
|
||||
"quiz_count_label": "Quizzes",
|
||||
"quiz_count_named": "{total} Quizzes",
|
||||
"quiz_count_label": "Quiz",
|
||||
"quiz_count_named": "{total} Quiz",
|
||||
|
||||
"history_title": "Quiz History",
|
||||
"history_subtitle": "Review the quizzes you've taken",
|
||||
|
@ -135,5 +135,23 @@
|
|||
"second": "{} s",
|
||||
"minute": "{} m",
|
||||
"hour": "{} h"
|
||||
}
|
||||
},
|
||||
|
||||
"get_ready": "Get Ready",
|
||||
"quiz_starting_soon": "Quiz Starting Soon",
|
||||
|
||||
"waiting_room": {
|
||||
"title": "Waiting Room",
|
||||
"participants_joined": "Participants Joined:",
|
||||
"leave_room": "Leave Room",
|
||||
"session_code": "Session Code:",
|
||||
"copy_code": "Copy Code",
|
||||
"quiz_info": "Quiz Information:",
|
||||
"quiz_title": "Title",
|
||||
"quiz_description": "Description",
|
||||
"quiz_total_question": "Total Questions",
|
||||
"quiz_duration": "Duration"
|
||||
},
|
||||
|
||||
"save_changes" : "Save Changes"
|
||||
}
|
||||
|
|
|
@ -119,5 +119,22 @@
|
|||
"second": "{} d",
|
||||
"minute": "{} m",
|
||||
"hour": "{} j"
|
||||
}
|
||||
},
|
||||
|
||||
"get_ready": "Bersiaplah",
|
||||
"quiz_starting_soon": "Kuis akan segera dimulai",
|
||||
"waiting_room": {
|
||||
"title": "Ruang Tunggu",
|
||||
"participants_joined": "Peserta Bergabung:",
|
||||
"leave_room": "Keluar dari Ruangan",
|
||||
"session_code": "Kode Sesi:",
|
||||
"copy_code": "Salin Kode",
|
||||
"quiz_info": "Informasi Kuis:",
|
||||
"quiz_title": "Judul",
|
||||
"quiz_description": "Deskripsi",
|
||||
"quiz_total_question": "Total Pertanyaan",
|
||||
"quiz_duration": "Durasi"
|
||||
},
|
||||
"save_changes": "Simpan Perubahan"
|
||||
|
||||
}
|
||||
|
|
|
@ -121,5 +121,21 @@
|
|||
"second": "{} s",
|
||||
"minute": "{} m",
|
||||
"hour": "{} j"
|
||||
}
|
||||
},
|
||||
|
||||
"get_ready": "Bersedia",
|
||||
"quiz_starting_soon": "Kuiz akan bermula sebentar lagi",
|
||||
"waiting_room": {
|
||||
"title": "Bilik Menunggu",
|
||||
"participants_joined": "Peserta Telah Sertai:",
|
||||
"leave_room": "Tinggalkan Bilik",
|
||||
"session_code": "Kod Sesi:",
|
||||
"copy_code": "Salin Kod",
|
||||
"quiz_info": "Maklumat Kuiz:",
|
||||
"quiz_title": "Tajuk",
|
||||
"quiz_description": "Penerangan",
|
||||
"quiz_total_question": "Jumlah Soalan",
|
||||
"quiz_duration": "Tempoh"
|
||||
},
|
||||
"save_changes": "Simpan Perubahan"
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class MyApp extends StatelessWidget {
|
|||
return GetMaterialApp(
|
||||
title: 'Quiz App',
|
||||
locale: Get.locale ?? context.locale,
|
||||
fallbackLocale: const Locale('en', 'US'),
|
||||
fallbackLocale: const Locale('id', 'ID'),
|
||||
localizationsDelegates: context.localizationDelegates,
|
||||
supportedLocales: context.supportedLocales,
|
||||
initialBinding: InitialBindings(),
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
extension StringCasingExtension on String {
|
||||
String toTitleCase() {
|
||||
return split(' ').map((word) => word.isNotEmpty ? '${word[0].toUpperCase()}${word.substring(1).toLowerCase()}' : '').join(' ');
|
||||
}
|
||||
}
|
|
@ -119,4 +119,88 @@ class AppDialog {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
static Future<bool?> showConfirmationDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String message,
|
||||
String cancelText = "Batal",
|
||||
String confirmText = "Yakin",
|
||||
Color confirmColor = AppColors.primaryBlue,
|
||||
}) async {
|
||||
return showDialog<bool>(
|
||||
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: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.darkText,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.softGrayText,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
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: Text(cancelText),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: confirmColor,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
),
|
||||
child: Text(confirmText),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class APIEndpoint {
|
||||
static const String baseUrl = "http://192.168.1.18:5000";
|
||||
// static const String baseUrl = "http://103.193.178.121:5000";
|
||||
// static const String baseUrl = "http://192.168.1.13:5000";
|
||||
static const String baseUrl = "http://103.193.178.121:5000";
|
||||
static const String api = "$baseUrl/api";
|
||||
|
||||
static const String login = "/login";
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
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 OverlayEntry? _overlayEntry;
|
||||
|
||||
static void showLoading(BuildContext context) {
|
||||
if (_overlayEntry != null) return;
|
||||
|
||||
_overlayEntry = OverlayEntry(
|
||||
builder: (_) => Stack(
|
||||
children: [
|
||||
ModalBarrier(
|
||||
dismissible: false,
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
),
|
||||
);
|
||||
},
|
||||
const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Overlay.of(context).insert(_overlayEntry!);
|
||||
}
|
||||
|
||||
static void hideLoadingDialog(BuildContext context) {
|
||||
Navigator.of(context).pop();
|
||||
static void hideLoading() {
|
||||
if (_overlayEntry?.mounted == true) {
|
||||
_overlayEntry?.remove();
|
||||
}
|
||||
_overlayEntry = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ class UserEntity {
|
|||
'pic_url': picUrl,
|
||||
'birth_date': birthDate,
|
||||
'locale': locale,
|
||||
"create_at": createdAt,
|
||||
'phone': phone,
|
||||
"created_at": createdAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:quiz_app/data/models/user/user_model.dart';
|
|||
class SessionInfo {
|
||||
final String id;
|
||||
final String sessionCode;
|
||||
final String roomName;
|
||||
final String quizId;
|
||||
final String hostId;
|
||||
final DateTime createdAt;
|
||||
|
@ -16,6 +17,7 @@ class SessionInfo {
|
|||
SessionInfo({
|
||||
required this.id,
|
||||
required this.sessionCode,
|
||||
required this.roomName,
|
||||
required this.quizId,
|
||||
required this.hostId,
|
||||
required this.createdAt,
|
||||
|
@ -31,6 +33,7 @@ class SessionInfo {
|
|||
return SessionInfo(
|
||||
id: json['id'],
|
||||
sessionCode: json['session_code'],
|
||||
roomName: json["room_name"],
|
||||
quizId: json['quiz_id'],
|
||||
hostId: json['host_id'],
|
||||
createdAt: DateTime.parse(json['created_at']),
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
class SessionRequestModel {
|
||||
final String quizId;
|
||||
final String hostId;
|
||||
final String roomName;
|
||||
final int limitParticipan;
|
||||
|
||||
SessionRequestModel({
|
||||
required this.quizId,
|
||||
required this.hostId,
|
||||
required this.roomName,
|
||||
required this.limitParticipan,
|
||||
});
|
||||
|
||||
|
@ -13,6 +15,7 @@ class SessionRequestModel {
|
|||
return SessionRequestModel(
|
||||
quizId: json['quiz_id'],
|
||||
hostId: json['host_id'],
|
||||
roomName: json['room_name'],
|
||||
limitParticipan: json['limit_participan'],
|
||||
);
|
||||
}
|
||||
|
@ -21,6 +24,7 @@ class SessionRequestModel {
|
|||
return {
|
||||
'quiz_id': quizId,
|
||||
'host_id': hostId,
|
||||
'room_name': roomName,
|
||||
'limit_participan': limitParticipan,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class ConnectionService extends GetxService {
|
|||
isConnected.value = results.any((result) => result != ConnectivityResult.none);
|
||||
}
|
||||
|
||||
Future<bool> checkConnection() async {
|
||||
Future<bool> isHaveConnection() async {
|
||||
final result = await _connectivity.checkConnectivity();
|
||||
return !result.contains(ConnectivityResult.none);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import 'dart:ui';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/core/endpoint/api_endpoint.dart';
|
||||
import 'package:quiz_app/core/utils/logger.dart';
|
||||
|
@ -82,7 +85,8 @@ class QuizService extends GetxService {
|
|||
|
||||
Future<BaseResponseModel<List<QuizListingModel>>?> populerQuiz({int page = 1, int amount = 3}) async {
|
||||
try {
|
||||
final response = await dio.get("${APIEndpoint.quizPopuler}?page=$page&limit=$amount");
|
||||
Locale locale = Localizations.localeOf(Get.context!);
|
||||
final response = await dio.get("${APIEndpoint.quizPopuler}?page=$page&limit=$amount&lang_code=${locale.languageCode}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final parsedResponse = BaseResponseModel<List<QuizListingModel>>.fromJson(
|
||||
|
@ -102,7 +106,8 @@ class QuizService extends GetxService {
|
|||
|
||||
Future<BaseResponseModel<List<QuizListingModel>>?> recommendationQuiz({int page = 1, int amount = 3, String userId = ""}) async {
|
||||
try {
|
||||
final response = await dio.get("${APIEndpoint.quizRecommendation}?page=$page&limit=$amount&user_id$userId");
|
||||
Locale locale = Localizations.localeOf(Get.context!);
|
||||
final response = await dio.get("${APIEndpoint.quizRecommendation}?page=$page&limit=$amount&user_id=$userId&lang_code=${locale.languageCode}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final parsedResponse = BaseResponseModel<List<QuizListingModel>>.fromJson(
|
||||
|
|
|
@ -17,11 +17,7 @@ class SessionService extends GetxService {
|
|||
|
||||
Future<BaseResponseModel<SessionResponseModel>?> createSession(SessionRequestModel data) async {
|
||||
try {
|
||||
final response = await _dio.post(APIEndpoint.session, data: {
|
||||
'quiz_id': data.quizId,
|
||||
'host_id': data.hostId,
|
||||
'limit_participan': data.limitParticipan,
|
||||
});
|
||||
final response = await _dio.post(APIEndpoint.session, data: data.toJson());
|
||||
if (response.statusCode != 201) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/feature/detail_quiz/controller/detail_quiz_controller.dart';
|
||||
|
||||
|
@ -8,6 +9,11 @@ class DetailQuizBinding extends Bindings {
|
|||
if (!Get.isRegistered<QuizService>()) {
|
||||
Get.lazyPut<QuizService>(() => QuizService());
|
||||
}
|
||||
Get.lazyPut<DetailQuizController>(() => DetailQuizController(Get.find<QuizService>()));
|
||||
Get.lazyPut<DetailQuizController>(
|
||||
() => DetailQuizController(
|
||||
Get.find<QuizService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/data/models/base/base_model.dart';
|
||||
import 'package:quiz_app/data/models/quiz/library_quiz_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
|
||||
class DetailQuizController extends GetxController {
|
||||
final QuizService _quizService;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
DetailQuizController(this._quizService);
|
||||
DetailQuizController(this._quizService, this._connectionService);
|
||||
|
||||
RxBool isLoading = true.obs;
|
||||
|
||||
late QuizData data;
|
||||
QuizData? data;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
|
@ -21,6 +24,11 @@ class DetailQuizController extends GetxController {
|
|||
|
||||
void loadData() async {
|
||||
final quizId = Get.arguments as String;
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
isLoading.value = false;
|
||||
return;
|
||||
}
|
||||
getQuizData(quizId);
|
||||
}
|
||||
|
||||
|
@ -32,5 +40,11 @@ class DetailQuizController extends GetxController {
|
|||
isLoading.value = false;
|
||||
}
|
||||
|
||||
void goToPlayPage() => Get.toNamed(AppRoutes.playQuizPage, arguments: data);
|
||||
void goToPlayPage() {
|
||||
if (!_connectionService.isCurrentlyConnected) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
Get.toNamed(AppRoutes.playQuizPage, arguments: data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,70 +30,76 @@ class DetailQuizView extends GetView<DetailQuizController> {
|
|||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Obx(
|
||||
() => controller.isLoading.value
|
||||
? const Center(child: LoadingWidget())
|
||||
: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header Section
|
||||
Text(
|
||||
controller.data.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.darkText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
controller.data.description ?? "",
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.softGrayText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today_rounded, size: 16, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
controller.data.date ?? "",
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.softGrayText),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Icon(Icons.timer_rounded, size: 16, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${controller.data.limitDuration ~/ 60} ${tr('minutes_suffix')}',
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.softGrayText),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
child: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(child: LoadingWidget());
|
||||
}
|
||||
|
||||
GlobalButton(text: tr('start_quiz'), onPressed: controller.goToPlayPage),
|
||||
const SizedBox(height: 20),
|
||||
if (controller.data == null) {
|
||||
return const Center(child: Text("Tidak Ditemukan"));
|
||||
}
|
||||
|
||||
const Divider(thickness: 1.2, color: AppColors.borderLight),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Soal Section
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: controller.data.questionListings.length,
|
||||
itemBuilder: (context, index) {
|
||||
final question = controller.data.questionListings[index];
|
||||
return _buildQuestionItem(question, index + 1);
|
||||
},
|
||||
),
|
||||
],
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header Section
|
||||
Text(
|
||||
controller.data!.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.darkText,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
controller.data!.description ?? "",
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.softGrayText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today_rounded, size: 16, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
controller.data!.date ?? "",
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.softGrayText),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Icon(Icons.timer_rounded, size: 16, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${controller.data!.limitDuration ~/ 60} ${tr('minutes_suffix')}',
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.softGrayText),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
GlobalButton(text: tr('start_quiz'), onPressed: controller.goToPlayPage),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
const Divider(thickness: 1.2, color: AppColors.borderLight),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Soal Section
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: controller.data!.questionListings.length,
|
||||
itemBuilder: (context, index) {
|
||||
final question = controller.data!.questionListings[index];
|
||||
return _buildQuestionItem(question, index + 1);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/history_service.dart';
|
||||
import 'package:quiz_app/feature/history/controller/history_controller.dart';
|
||||
|
||||
|
@ -7,6 +8,12 @@ class HistoryBinding extends Bindings {
|
|||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<HistoryService>(() => HistoryService());
|
||||
Get.lazyPut(() => HistoryController(Get.find<HistoryService>(), Get.find<UserController>()));
|
||||
Get.lazyPut(
|
||||
() => HistoryController(
|
||||
Get.find<HistoryService>(),
|
||||
Get.find<UserController>(),
|
||||
Get.find<ConnectionService>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/models/history/quiz_history.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/history_service.dart';
|
||||
|
||||
class HistoryController extends GetxController {
|
||||
final HistoryService _historyService;
|
||||
final UserController _userController;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
HistoryController(this._historyService, this._userController);
|
||||
HistoryController(
|
||||
this._historyService,
|
||||
this._userController,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
RxBool isLoading = true.obs;
|
||||
|
||||
|
@ -17,10 +24,15 @@ class HistoryController extends GetxController {
|
|||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadDummyHistory();
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
void loadDummyHistory() async {
|
||||
void loadHistory() async {
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
historyList.value = await _historyService.getHistory(_userController.userData!.id) ?? [];
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
|
|
@ -43,15 +43,17 @@ class DetailHistoryView extends GetView<DetailHistoryController> {
|
|||
|
||||
List<Widget> quizListings() {
|
||||
return controller.quizAnswer.questionListings
|
||||
.map((e) => QuizItemWAComponent(
|
||||
index: e.index,
|
||||
isCorrect: e.isCorrect,
|
||||
question: e.question,
|
||||
targetAnswer: e.targetAnswer,
|
||||
timeSpent: e.timeSpent,
|
||||
type: e.type,
|
||||
userAnswer: e.userAnswer,
|
||||
options: e.options,
|
||||
.asMap()
|
||||
.entries
|
||||
.map((entry) => QuizItemWAComponent(
|
||||
index: entry.key + 1,
|
||||
isCorrect: entry.value.isCorrect,
|
||||
question: entry.value.question,
|
||||
targetAnswer: entry.value.targetAnswer,
|
||||
timeSpent: entry.value.timeSpent,
|
||||
type: entry.value.type,
|
||||
userAnswer: entry.value.userAnswer,
|
||||
options: entry.value.options,
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
|
|
|
@ -16,11 +16,14 @@ class HistoryView extends GetView<HistoryController> {
|
|||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(context.tr("history_title"), style: AppTextStyles.title.copyWith(fontSize: 24)),
|
||||
Text(
|
||||
context.tr("history_title"),
|
||||
style: AppTextStyles.title.copyWith(fontSize: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
context.tr("history_subtitle"),
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/data/services/subject_service.dart';
|
||||
import 'package:quiz_app/feature/home/controller/home_controller.dart';
|
||||
|
@ -10,8 +12,10 @@ class HomeBinding extends Bindings {
|
|||
Get.lazyPut<SubjectService>(() => SubjectService());
|
||||
Get.lazyPut<HomeController>(
|
||||
() => HomeController(
|
||||
Get.find<UserController>(),
|
||||
Get.find<QuizService>(),
|
||||
Get.find<SubjectService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,28 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/const/enums/listing_type.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/core/utils/logger.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/models/base/base_model.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiz_listing_model.dart';
|
||||
import 'package:quiz_app/data/models/subject/subject_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/data/services/subject_service.dart';
|
||||
import 'package:quiz_app/feature/navigation/controllers/navigation_controller.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
final UserController _userController = Get.find<UserController>();
|
||||
|
||||
final UserController _userController;
|
||||
final QuizService _quizService;
|
||||
final SubjectService _subjectService;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
HomeController(
|
||||
this._userController,
|
||||
this._quizService,
|
||||
this._subjectService,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
RxInt timeStatus = 1.obs;
|
||||
|
@ -39,6 +43,10 @@ class HomeController extends GetxController {
|
|||
}
|
||||
|
||||
void _getRecomendationQuiz() async {
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
BaseResponseModel? response = await _quizService.recommendationQuiz(userId: _userController.userData!.id);
|
||||
if (response != null) {
|
||||
data.assignAll(response.data as List<QuizListingModel>);
|
||||
|
@ -46,6 +54,7 @@ class HomeController extends GetxController {
|
|||
}
|
||||
|
||||
void loadSubjectData() async {
|
||||
if (!_connectionService.isCurrentlyConnected) return;
|
||||
try {
|
||||
final response = await _subjectService.getSubject();
|
||||
subjects.assignAll(response.data!);
|
||||
|
|
|
@ -5,6 +5,7 @@ class UserGretingsComponent extends StatelessWidget {
|
|||
final String userName;
|
||||
final String? userImage;
|
||||
final int greatingStatus;
|
||||
|
||||
const UserGretingsComponent({
|
||||
super.key,
|
||||
required this.userName,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/socket_service.dart';
|
||||
import 'package:quiz_app/feature/join_room/controller/join_room_controller.dart';
|
||||
|
||||
|
@ -8,6 +9,12 @@ class JoinRoomBinding extends Bindings {
|
|||
void dependencies() {
|
||||
Get.put(SocketService());
|
||||
|
||||
Get.lazyPut(() => JoinRoomController(Get.find<SocketService>(), Get.find<UserController>()));
|
||||
Get.lazyPut(
|
||||
() => JoinRoomController(
|
||||
Get.find<SocketService>(),
|
||||
Get.find<UserController>(),
|
||||
Get.find<ConnectionService>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,36 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/core/utils/custom_floating_loading.dart';
|
||||
import 'package:quiz_app/core/utils/custom_notification.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';
|
||||
import 'package:quiz_app/data/models/session/session_info_model.dart';
|
||||
import 'package:quiz_app/data/models/session/session_response_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/socket_service.dart';
|
||||
|
||||
class JoinRoomController extends GetxController {
|
||||
final SocketService _socketService;
|
||||
final UserController _userController;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
JoinRoomController(this._socketService, this._userController);
|
||||
JoinRoomController(
|
||||
this._socketService,
|
||||
this._userController,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
final TextEditingController codeController = TextEditingController();
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
void joinRoom() {
|
||||
void joinRoom(BuildContext context) {
|
||||
if (!_connectionService.isCurrentlyConnected) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
final code = codeController.text.trim();
|
||||
|
||||
if (code.isEmpty) {
|
||||
|
@ -29,18 +42,15 @@ class JoinRoomController extends GetxController {
|
|||
);
|
||||
return;
|
||||
}
|
||||
CustomFloatingLoading.showLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
isLoading.value = true;
|
||||
_socketService.initSocketConnection();
|
||||
|
||||
_socketService.joinRoom(sessionCode: code, userId: _userController.userData!.id);
|
||||
_socketService.errors.listen((error) {
|
||||
Get.snackbar(
|
||||
"not found",
|
||||
"Ruangan tidak ditemukan",
|
||||
backgroundColor: Get.theme.colorScheme.error.withValues(alpha: 0.9),
|
||||
colorText: Colors.white,
|
||||
);
|
||||
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
CustomNotification.error(title: "not found", message: "Ruangan tidak ditemukan");
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
});
|
||||
|
||||
_socketService.roomMessages.listen((data) {
|
||||
|
@ -49,7 +59,8 @@ class JoinRoomController extends GetxController {
|
|||
final Map<String, dynamic> sessionInfoJson = dataPayload["session_info"];
|
||||
final Map<String, dynamic> quizInfoJson = dataPayload["quiz_info"];
|
||||
|
||||
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
Get.toNamed(
|
||||
AppRoutes.waitRoomPage,
|
||||
arguments: WaitingRoomDTO(
|
||||
|
@ -66,6 +77,10 @@ class JoinRoomController extends GetxController {
|
|||
});
|
||||
}
|
||||
|
||||
void onGoBack() {
|
||||
if (!isLoading.value) Get.back();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
codeController.dispose();
|
||||
|
|
|
@ -12,185 +12,189 @@ class JoinRoomView extends GetView<JoinRoomController> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(LucideIcons.arrowLeft, color: Colors.black87),
|
||||
onPressed: () => Get.back(),
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) => controller.onGoBack(),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(LucideIcons.arrowLeft, color: Colors.black87),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
color: Colors.white,
|
||||
child: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
body: Container(
|
||||
color: Colors.white,
|
||||
child: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
|
||||
TweenAnimationBuilder<double>(
|
||||
duration: const Duration(seconds: 1),
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
builder: (context, value, child) {
|
||||
return Transform.scale(
|
||||
scale: value,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(22),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryBlue.withValues(alpha: 0.05),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColors.primaryBlue.withValues(alpha: 0.15),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
LucideIcons.trophy,
|
||||
size: 70,
|
||||
color: AppColors.primaryBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
// TweenAnimationBuilder<double>(
|
||||
// duration: const Duration(seconds: 1),
|
||||
// tween: Tween(begin: 0.0, end: 1.0),
|
||||
// builder: (context, value, child) {
|
||||
// return Transform.scale(
|
||||
// scale: value,
|
||||
// child: child,
|
||||
// );
|
||||
// },
|
||||
// child: Container(
|
||||
// padding: EdgeInsets.all(22),
|
||||
// decoration: BoxDecoration(
|
||||
// color: AppColors.primaryBlue.withValues(alpha: 0.05),
|
||||
// shape: BoxShape.circle,
|
||||
// border: Border.all(
|
||||
// color: AppColors.primaryBlue.withValues(alpha: 0.15),
|
||||
// width: 2,
|
||||
// ),
|
||||
// ),
|
||||
// child: Icon(
|
||||
// LucideIcons.trophy,
|
||||
// size: 70,
|
||||
// color: AppColors.primaryBlue,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
|
||||
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: Transform.translate(
|
||||
offset: Offset(0, 20 * (1 - value)),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
context.tr("ready_to_compete"),
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Animated Subtitle
|
||||
TweenAnimationBuilder<double>(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
builder: (context, value, child) {
|
||||
return Opacity(
|
||||
opacity: value,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, 20 * (1 - value)),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
TweenAnimationBuilder<double>(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
builder: (context, value, child) {
|
||||
return Opacity(
|
||||
opacity: value,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, 20 * (1 - value)),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
context.tr("enter_code_to_join"),
|
||||
context.tr("ready_to_compete"),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.black54,
|
||||
height: 1.4,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 40),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
TweenAnimationBuilder<double>(
|
||||
duration: const Duration(milliseconds: 1000),
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
builder: (context, value, child) {
|
||||
return Opacity(
|
||||
opacity: value,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, 30 * (1 - value)),
|
||||
child: child,
|
||||
// Animated Subtitle
|
||||
TweenAnimationBuilder<double>(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
builder: (context, value, child) {
|
||||
return Opacity(
|
||||
opacity: value,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, 20 * (1 - value)),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(
|
||||
context.tr("enter_code_to_join"),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.black54,
|
||||
height: 1.4,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 30),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withValues(alpha: 0.08),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.keySquare,
|
||||
color: AppColors.primaryBlue,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
context.tr("enter_room_code"),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade200,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: GlobalTextField(
|
||||
controller: controller.codeController,
|
||||
hintText: context.tr("room_code_hint"),
|
||||
textInputType: TextInputType.text,
|
||||
forceUpperCase: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
GlobalButton(
|
||||
text: context.tr("join_quiz_now"),
|
||||
onPressed: controller.joinRoom,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 30),
|
||||
],
|
||||
const SizedBox(height: 40),
|
||||
|
||||
TweenAnimationBuilder<double>(
|
||||
duration: const Duration(milliseconds: 1000),
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
builder: (context, value, child) {
|
||||
return Opacity(
|
||||
opacity: value,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, 30 * (1 - value)),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 30),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withValues(alpha: 0.08),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.keySquare,
|
||||
color: AppColors.primaryBlue,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
context.tr("enter_room_code"),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade200,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: GlobalTextField(
|
||||
controller: controller.codeController,
|
||||
hintText: context.tr("room_code_hint"),
|
||||
textInputType: TextInputType.text,
|
||||
forceUpperCase: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
GlobalButton(
|
||||
text: context.tr("join_quiz_now"),
|
||||
onPressed: () => controller.joinRoom(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/feature/library/controller/library_controller.dart';
|
||||
|
||||
|
@ -9,6 +10,10 @@ class LibraryBinding extends Bindings {
|
|||
if (!Get.isRegistered<QuizService>()) {
|
||||
Get.lazyPut<QuizService>(() => QuizService());
|
||||
}
|
||||
Get.lazyPut<LibraryController>(() => LibraryController(Get.find<QuizService>(), Get.find<UserController>()));
|
||||
Get.lazyPut<LibraryController>(() => LibraryController(
|
||||
Get.find<QuizService>(),
|
||||
Get.find<UserController>(),
|
||||
Get.find<ConnectionService>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/models/base/base_model.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiz_listing_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
|
||||
class LibraryController extends GetxController {
|
||||
final QuizService _quizService;
|
||||
final UserController _userController;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
LibraryController(
|
||||
this._quizService,
|
||||
this._userController,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
RxList<QuizListingModel> quizs = <QuizListingModel>[].obs;
|
||||
RxBool isLoading = true.obs;
|
||||
RxString emptyMessage = "".obs;
|
||||
|
||||
final QuizService _quizService;
|
||||
final UserController _userController;
|
||||
LibraryController(this._quizService, this._userController);
|
||||
|
||||
int currentPage = 1;
|
||||
|
||||
@override
|
||||
|
@ -23,6 +30,10 @@ class LibraryController extends GetxController {
|
|||
}
|
||||
|
||||
void loadUserQuiz() async {
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
isLoading.value = true;
|
||||
BaseResponseModel<List<QuizListingModel>>? response = await _quizService.userQuiz(_userController.userData!.id, currentPage);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:quiz_app/app/const/text/text_style.dart';
|
||||
import 'package:quiz_app/component/widget/container_skeleton_widget.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiz_listing_model.dart';
|
||||
import 'package:quiz_app/feature/library/controller/library_controller.dart';
|
||||
import 'package:quiz_app/app/const/colors/app_colors.dart';
|
||||
|
||||
class LibraryView extends GetView<LibraryController> {
|
||||
const LibraryView({super.key});
|
||||
|
@ -11,7 +13,7 @@ class LibraryView extends GetView<LibraryController> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF9FAFB),
|
||||
backgroundColor: AppColors.background2,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
|
@ -20,19 +22,12 @@ class LibraryView extends GetView<LibraryController> {
|
|||
children: [
|
||||
Text(
|
||||
context.tr('library_title'),
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 24,
|
||||
),
|
||||
style: AppTextStyles.title.copyWith(fontSize: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
context.tr('library_description'),
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 14,
|
||||
),
|
||||
style: AppTextStyles.subtitle,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Expanded(
|
||||
|
@ -50,7 +45,7 @@ class LibraryView extends GetView<LibraryController> {
|
|||
return Center(
|
||||
child: Text(
|
||||
context.tr('no_quiz_available'),
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 14),
|
||||
style: AppTextStyles.caption,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -79,7 +74,7 @@ class LibraryView extends GetView<LibraryController> {
|
|||
margin: const EdgeInsets.only(bottom: 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
|
@ -95,7 +90,7 @@ class LibraryView extends GetView<LibraryController> {
|
|||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2563EB),
|
||||
color: AppColors.primaryBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(Icons.menu_book_rounded, color: Colors.white),
|
||||
|
@ -107,46 +102,42 @@ class LibraryView extends GetView<LibraryController> {
|
|||
children: [
|
||||
Text(
|
||||
quiz.title,
|
||||
style: const TextStyle(
|
||||
style: AppTextStyles.body.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: Colors.black,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
quiz.description,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 12,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
style: AppTextStyles.caption,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today_rounded, size: 14, color: Colors.grey),
|
||||
const Icon(Icons.calendar_today_rounded, size: 14, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
controller.formatDate(quiz.date),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
style: AppTextStyles.dateTime,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Icon(Icons.list, size: 14, color: Colors.grey),
|
||||
const Icon(Icons.list, size: 14, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
context.tr('quiz_count_named', namedArgs: {'total': quiz.totalQuiz.toString()}),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
style: AppTextStyles.dateTime,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Icon(Icons.access_time, size: 14, color: Colors.grey),
|
||||
const Icon(Icons.access_time, size: 14, color: AppColors.softGrayText),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
controller.formatDuration(quiz.duration),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
style: AppTextStyles.dateTime,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:get/get.dart';
|
|||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/component/global_button.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.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';
|
||||
|
@ -36,13 +37,15 @@ class LoginController extends GetxController {
|
|||
final RxBool isPasswordHidden = true.obs;
|
||||
final RxBool isLoading = false.obs;
|
||||
|
||||
late Worker _connectionWorker;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
emailController.addListener(validateFields);
|
||||
passwordController.addListener(validateFields);
|
||||
|
||||
ever(_connectionService.isConnected, (value) {
|
||||
_connectionWorker = ever(_connectionService.isConnected, (value) {
|
||||
if (!value) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
} else {
|
||||
|
@ -87,6 +90,7 @@ class LoginController extends GetxController {
|
|||
}
|
||||
try {
|
||||
isLoading.value = true;
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
|
||||
final LoginResponseModel response = await _authService.loginWithEmail(
|
||||
LoginRequestModel(email: email, password: password),
|
||||
|
@ -97,13 +101,14 @@ class LoginController extends GetxController {
|
|||
await _userStorageService.saveUser(userEntity);
|
||||
_userController.setUserFromEntity(userEntity);
|
||||
_userStorageService.isLogged = true;
|
||||
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
Get.offAllNamed(AppRoutes.mainPage);
|
||||
} catch (e, stackTrace) {
|
||||
logC.e(e, stackTrace: stackTrace);
|
||||
CustomNotification.error(title: "Gagal", message: "Periksa kembali email dan kata sandi Anda");
|
||||
} finally {
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
CustomNotification.error(title: "Gagal", message: "Periksa kembali email dan kata sandi Anda");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,15 +118,23 @@ class LoginController extends GetxController {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
isLoading.value = true;
|
||||
final user = await _googleAuthService.signIn();
|
||||
if (user == null) {
|
||||
Get.snackbar("Kesalahan", "Masuk dengan Google dibatalkan");
|
||||
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
final idToken = await user.authentication.then((auth) => auth.idToken);
|
||||
if (idToken == null || idToken.isEmpty) {
|
||||
Get.snackbar("Kesalahan", "Tidak menerima ID Token dari Google");
|
||||
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -131,18 +144,25 @@ class LoginController extends GetxController {
|
|||
await _userStorageService.saveUser(userEntity);
|
||||
_userController.setUserFromEntity(userEntity);
|
||||
_userStorageService.isLogged = true;
|
||||
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
Get.offAllNamed(AppRoutes.mainPage);
|
||||
} catch (e, stackTrace) {
|
||||
logC.e("Google Sign-In Error: $e", stackTrace: stackTrace);
|
||||
Get.snackbar("Error", "Google sign-in error");
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void onGoBack() {
|
||||
if (!isLoading.value) Get.back();
|
||||
}
|
||||
|
||||
void goToRegsPage() => Get.toNamed(AppRoutes.registerPage);
|
||||
|
||||
UserEntity _convertLoginResponseToUserEntity(LoginResponseModel response) {
|
||||
logC.i("user id : ${response.id}");
|
||||
logC.i("user data ${response.toJson()}");
|
||||
return UserEntity(
|
||||
id: response.id ?? '',
|
||||
name: response.name,
|
||||
|
@ -154,4 +174,10 @@ class LoginController extends GetxController {
|
|||
phone: response.phone,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_connectionWorker.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,70 +15,74 @@ class LoginView extends GetView<LoginController> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
child: ListView(
|
||||
children: [
|
||||
const SizedBox(height: 40),
|
||||
const AppName(),
|
||||
const SizedBox(height: 40),
|
||||
LabelTextField(
|
||||
label: context.tr("log_in"),
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF172B4D),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
LabelTextField(
|
||||
label: context.tr("email"),
|
||||
color: Color(0xFF6B778C),
|
||||
fontSize: 14,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
GlobalTextField(
|
||||
controller: controller.emailController,
|
||||
hintText: context.tr("enter_your_email"),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
LabelTextField(
|
||||
label: context.tr("password"),
|
||||
color: Color(0xFF6B778C),
|
||||
fontSize: 14,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Obx(
|
||||
() => GlobalTextField(
|
||||
controller: controller.passwordController,
|
||||
isPassword: true,
|
||||
obscureText: controller.isPasswordHidden.value,
|
||||
onToggleVisibility: controller.togglePasswordVisibility,
|
||||
hintText: context.tr("enter_your_password"),
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) => controller.onGoBack(),
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
child: ListView(
|
||||
children: [
|
||||
const SizedBox(height: 40),
|
||||
const AppName(),
|
||||
const SizedBox(height: 40),
|
||||
LabelTextField(
|
||||
label: context.tr("log_in"),
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF172B4D),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Obx(() => GlobalButton(
|
||||
onPressed: controller.loginWithEmail,
|
||||
text: context.tr("sign_in"),
|
||||
type: controller.isButtonEnabled.value,
|
||||
)),
|
||||
const SizedBox(height: 24),
|
||||
LabelTextField(
|
||||
label: context.tr("or"),
|
||||
alignment: Alignment.center,
|
||||
color: Color(0xFF6B778C),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
GoogleButton(
|
||||
onPress: controller.loginWithGoogle,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
RegisterTextButton(
|
||||
onTap: controller.goToRegsPage,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
LabelTextField(
|
||||
label: context.tr("email"),
|
||||
color: Color(0xFF6B778C),
|
||||
fontSize: 14,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
GlobalTextField(
|
||||
controller: controller.emailController,
|
||||
hintText: context.tr("enter_your_email"),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
LabelTextField(
|
||||
label: context.tr("password"),
|
||||
color: Color(0xFF6B778C),
|
||||
fontSize: 14,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Obx(
|
||||
() => GlobalTextField(
|
||||
controller: controller.passwordController,
|
||||
isPassword: true,
|
||||
obscureText: controller.isPasswordHidden.value,
|
||||
onToggleVisibility: controller.togglePasswordVisibility,
|
||||
hintText: context.tr("enter_your_password"),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Obx(() => GlobalButton(
|
||||
onPressed: controller.loginWithEmail,
|
||||
text: context.tr("sign_in"),
|
||||
type: controller.isButtonEnabled.value,
|
||||
)),
|
||||
const SizedBox(height: 24),
|
||||
LabelTextField(
|
||||
label: context.tr("or"),
|
||||
alignment: Alignment.center,
|
||||
color: Color(0xFF6B778C),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
GoogleButton(
|
||||
onPress: controller.loginWithGoogle,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
RegisterTextButton(
|
||||
onTap: controller.goToRegsPage,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
// feature/navbar/binding/navbar_binding.dart
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/feature/navigation/controllers/navigation_controller.dart';
|
||||
|
||||
class NavbarBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<NavigationController>(() => NavigationController());
|
||||
Get.lazyPut<NavigationController>(() => NavigationController(Get.find<ConnectionService>()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
|
||||
class NavigationController extends GetxController {
|
||||
RxInt selectedIndex = 0.obs;
|
||||
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
NavigationController(this._connectionService);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
@ -12,6 +18,18 @@ class NavigationController extends GetxController {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
ever(_connectionService.isConnected, (value) {
|
||||
if (!value) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
} else {
|
||||
ConnectionNotification.internetConnected();
|
||||
}
|
||||
});
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
void changePage(int page) {
|
||||
selectedIndex.value = page;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/google_auth_service.dart';
|
||||
import 'package:quiz_app/data/services/user_service.dart';
|
||||
import 'package:quiz_app/data/services/user_storage_service.dart';
|
||||
|
@ -15,6 +16,7 @@ class ProfileBinding extends Bindings {
|
|||
Get.find<UserStorageService>(),
|
||||
Get.find<GoogleAuthService>(),
|
||||
Get.find<UserService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/user_service.dart';
|
||||
import 'package:quiz_app/data/services/user_storage_service.dart';
|
||||
import 'package:quiz_app/feature/profile/controller/update_profile_controller.dart';
|
||||
|
@ -12,6 +13,7 @@ class UpdateProfileBinding extends Bindings {
|
|||
Get.find<UserService>(),
|
||||
Get.find<UserController>(),
|
||||
Get.find<UserStorageService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/component/notification/pop_up_confirmation.dart';
|
||||
import 'package:quiz_app/core/endpoint/api_endpoint.dart';
|
||||
import 'package:quiz_app/core/utils/logger.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/models/user/user_stat_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/google_auth_service.dart';
|
||||
import 'package:quiz_app/data/services/user_service.dart';
|
||||
import 'package:quiz_app/data/services/user_storage_service.dart';
|
||||
|
@ -17,12 +19,14 @@ class ProfileController extends GetxController {
|
|||
final UserStorageService _userStorageService;
|
||||
final GoogleAuthService _googleAuthService;
|
||||
final UserService _userService;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
ProfileController(
|
||||
this._userController,
|
||||
this._userStorageService,
|
||||
this._googleAuthService,
|
||||
this._userService,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
// User basic info
|
||||
|
@ -73,6 +77,9 @@ class ProfileController extends GetxController {
|
|||
}
|
||||
|
||||
void loadUserStat() async {
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final result = await _userService.getUserStat(_userController.userData!.id);
|
||||
if (result != null) {
|
||||
|
@ -83,21 +90,34 @@ class ProfileController extends GetxController {
|
|||
}
|
||||
}
|
||||
|
||||
void logout() async {
|
||||
try {
|
||||
await _googleAuthService.signOut();
|
||||
await _userStorageService.clearUser();
|
||||
_userController.clearUser();
|
||||
_userStorageService.isLogged = false;
|
||||
Get.offAllNamed(AppRoutes.loginPage);
|
||||
} catch (e, stackTrace) {
|
||||
logC.e("Google Sign-Out Error: $e", stackTrace: stackTrace);
|
||||
Get.snackbar("Error", "Gagal logout dari Google");
|
||||
void logout(BuildContext context) async {
|
||||
final confirm = await AppDialog.showConfirmationDialog(
|
||||
context,
|
||||
title: "Keluar dari akun?",
|
||||
message: "Apakah Anda yakin ingin logout dari akun ini?",
|
||||
confirmText: "Logout",
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
try {
|
||||
await _googleAuthService.signOut();
|
||||
await _userStorageService.clearUser();
|
||||
_userController.clearUser();
|
||||
_userStorageService.isLogged = false;
|
||||
Get.offAllNamed(AppRoutes.loginPage);
|
||||
} catch (e, stackTrace) {
|
||||
logC.e("Google Sign-Out Error: $e", stackTrace: stackTrace);
|
||||
Get.snackbar("Error", "Gagal logout dari Google");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void editProfile() {
|
||||
Get.toNamed(AppRoutes.updateProfilePage);
|
||||
void editProfile() async {
|
||||
final resultUpdate = await Get.toNamed(AppRoutes.updateProfilePage);
|
||||
|
||||
if (resultUpdate == true) {
|
||||
loadUserProfileData();
|
||||
}
|
||||
}
|
||||
|
||||
void changeLanguage(BuildContext context, String languageCode, String countryCode) async {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.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';
|
||||
import 'package:quiz_app/data/entity/user/user_entity.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/user_service.dart';
|
||||
import 'package:quiz_app/data/services/user_storage_service.dart';
|
||||
|
||||
|
@ -11,11 +14,13 @@ class UpdateProfileController extends GetxController {
|
|||
final UserController _userController;
|
||||
final UserStorageService _userStorageService;
|
||||
final UserService _userService;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
UpdateProfileController(
|
||||
this._userService,
|
||||
this._userController,
|
||||
this._userStorageService,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
final nameController = TextEditingController();
|
||||
|
@ -24,6 +29,8 @@ class UpdateProfileController extends GetxController {
|
|||
|
||||
var selectedLocale = 'en-US'.obs;
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
final Map<String, String> localeMap = {
|
||||
'English': 'en-US',
|
||||
'Indonesian': 'id-ID',
|
||||
|
@ -44,65 +51,86 @@ class UpdateProfileController extends GetxController {
|
|||
final name = nameController.text.trim();
|
||||
final phone = phoneController.text.trim();
|
||||
final birthDate = birthDateController.text.trim();
|
||||
print(birthDate);
|
||||
|
||||
if (name.isEmpty || phone.isEmpty || birthDate.isEmpty) {
|
||||
Get.snackbar('Validation Error', 'All fields must be filled.', snackPosition: SnackPosition.TOP);
|
||||
CustomNotification.error(
|
||||
title: 'Validation Error',
|
||||
message: 'All fields must be filled.',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_isValidDateFormat(birthDate)) {
|
||||
Get.snackbar('Validation Error', 'birth date must valid.', snackPosition: SnackPosition.TOP);
|
||||
CustomNotification.error(
|
||||
title: 'Validation Error',
|
||||
message: 'birth date must valid.',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> saveProfile() async {
|
||||
if (!_validateInputs()) return;
|
||||
|
||||
CustomFloatingLoading.showLoadingDialog(Get.context!);
|
||||
|
||||
final isSuccessUpdate = await _userService.updateProfileData(
|
||||
_userController.userData!.id,
|
||||
nameController.text.trim(),
|
||||
birthDate: birthDateController.text.trim(),
|
||||
phone: phoneController.text.trim(),
|
||||
locale: selectedLocale.value,
|
||||
);
|
||||
|
||||
if (isSuccessUpdate) {
|
||||
final response = await _userService.getUserData(_userController.userData!.id);
|
||||
|
||||
if (response?.data != null) {
|
||||
final userNew = response!.data!;
|
||||
final newUser = UserEntity(
|
||||
id: userNew.id,
|
||||
email: userNew.email,
|
||||
name: userNew.name,
|
||||
birthDate: userNew.birthDate,
|
||||
locale: userNew.locale,
|
||||
picUrl: userNew.picUrl,
|
||||
phone: userNew.phone,
|
||||
);
|
||||
|
||||
_userStorageService.saveUser(newUser);
|
||||
_userController.userData = newUser;
|
||||
|
||||
_userController.email.value = userNew.email;
|
||||
_userController.userName.value = userNew.name;
|
||||
_userController.userImage.value = userNew.picUrl;
|
||||
}
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
Get.back();
|
||||
if (!_validateInputs()) return;
|
||||
|
||||
CustomNotification.success(title: "Success", message: "Profile updated successfully");
|
||||
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
try {
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
isLoading.value = true;
|
||||
final isSuccessUpdate = await _userService.updateProfileData(
|
||||
_userController.userData!.id,
|
||||
nameController.text.trim(),
|
||||
birthDate: birthDateController.text.trim(),
|
||||
phone: phoneController.text.trim(),
|
||||
locale: selectedLocale.value,
|
||||
);
|
||||
|
||||
if (isSuccessUpdate) {
|
||||
final response = await _userService.getUserData(_userController.userData!.id);
|
||||
|
||||
if (response?.data != null) {
|
||||
final userNew = response!.data!;
|
||||
final newUser = UserEntity(
|
||||
id: userNew.id,
|
||||
email: userNew.email,
|
||||
name: userNew.name,
|
||||
birthDate: userNew.birthDate,
|
||||
locale: userNew.locale,
|
||||
picUrl: userNew.picUrl,
|
||||
phone: userNew.phone,
|
||||
createdAt: userNew.createdAt,
|
||||
);
|
||||
|
||||
_userStorageService.saveUser(newUser);
|
||||
_userController.userData = newUser;
|
||||
|
||||
_userController.email.value = userNew.email;
|
||||
_userController.userName.value = userNew.name;
|
||||
_userController.userImage.value = userNew.picUrl;
|
||||
}
|
||||
}
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
|
||||
Get.back(result: true);
|
||||
CustomNotification.success(title: "Success", message: "Profile updated successfully");
|
||||
} catch (e) {
|
||||
CustomNotification.success(title: "something wrong", message: "failed to update profile");
|
||||
isLoading.value = false;
|
||||
logC.e(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool _isValidDateFormat(String date) {
|
||||
final regex = RegExp(r'^([0-2][0-9]|(3)[0-1])\-((0[1-9])|(1[0-2]))\-\d{4}$');
|
||||
return regex.hasMatch(date);
|
||||
}
|
||||
|
||||
void onGoBack() {
|
||||
if (!isLoading.value) Get.back();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class ProfileView extends GetView<ProfileController> {
|
|||
const SizedBox(height: 10),
|
||||
_profileDetails(cardRadius: cardRadius),
|
||||
const SizedBox(height: 10),
|
||||
_settingsSection(cardRadius: cardRadius),
|
||||
_settingsSection(context, cardRadius: cardRadius),
|
||||
const SizedBox(height: 10),
|
||||
_legalSection(cardRadius: cardRadius),
|
||||
const SizedBox(height: 20),
|
||||
|
@ -161,7 +161,7 @@ class ProfileView extends GetView<ProfileController> {
|
|||
),
|
||||
);
|
||||
|
||||
Widget _settingsSection({required BorderRadius cardRadius}) => Card(
|
||||
Widget _settingsSection(BuildContext context, {required BorderRadius cardRadius}) => Card(
|
||||
color: Colors.white,
|
||||
elevation: 1,
|
||||
shadowColor: AppColors.shadowPrimary,
|
||||
|
@ -177,7 +177,7 @@ class ProfileView extends GetView<ProfileController> {
|
|||
const Divider(height: 1),
|
||||
_settingsTile(Get.context!, icon: LucideIcons.languages, title: tr('change_language'), onTap: () => _showLanguageDialog(Get.context!)),
|
||||
_settingsTile(Get.context!,
|
||||
icon: LucideIcons.logOut, title: tr('logout'), iconColor: Colors.red, textColor: Colors.red, onTap: controller.logout),
|
||||
icon: LucideIcons.logOut, title: tr('logout'), iconColor: Colors.red, textColor: Colors.red, onTap: () => controller.logout(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/const/colors/app_colors.dart';
|
||||
import 'package:quiz_app/component/global_button.dart';
|
||||
import 'package:quiz_app/component/global_dropdown_field.dart';
|
||||
import 'package:quiz_app/component/global_text_field.dart';
|
||||
|
@ -9,56 +11,62 @@ import 'package:quiz_app/feature/profile/controller/update_profile_controller.da
|
|||
class UpdateProfilePage extends GetView<UpdateProfileController> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Update Profile'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
LabelTextField(label: "Name"),
|
||||
GlobalTextField(controller: controller.nameController),
|
||||
SizedBox(height: 16),
|
||||
LabelTextField(label: "Phone"),
|
||||
GlobalTextField(
|
||||
controller: controller.phoneController,
|
||||
hintText: 'Enter your phone number',
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
LabelTextField(label: "Birth Date"),
|
||||
GlobalTextField(
|
||||
controller: controller.birthDateController,
|
||||
hintText: 'Enter your birth date',
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
LabelTextField(label: "Locale"),
|
||||
Obx(() => GlobalDropdownField<String>(
|
||||
value: controller.selectedLocale.value,
|
||||
items: controller.localeMap.entries.map<DropdownMenuItem<String>>((entry) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: entry.value,
|
||||
child: Text(entry.key), // Display country name
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue != null) {
|
||||
controller.selectedLocale.value = newValue;
|
||||
final parts = newValue.split('-');
|
||||
if (parts.length == 2) {
|
||||
Get.updateLocale(Locale(parts[0], parts[1]));
|
||||
} else {
|
||||
Get.updateLocale(Locale(newValue));
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) => controller.onGoBack(),
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background2,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColors.background2,
|
||||
title: Text('Update Profile'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
LabelTextField(label: "Name"),
|
||||
GlobalTextField(controller: controller.nameController),
|
||||
SizedBox(height: 16),
|
||||
LabelTextField(label: "Phone"),
|
||||
GlobalTextField(
|
||||
controller: controller.phoneController,
|
||||
hintText: 'Enter your phone number',
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
LabelTextField(label: "Birth Date"),
|
||||
GlobalTextField(
|
||||
controller: controller.birthDateController,
|
||||
hintText: 'Enter your birth date',
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
LabelTextField(label: "Locale"),
|
||||
Obx(() => GlobalDropdownField<String>(
|
||||
value: controller.selectedLocale.value,
|
||||
items: controller.localeMap.entries.map<DropdownMenuItem<String>>((entry) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: entry.value,
|
||||
child: Text(entry.key), // Display country name
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue != null) {
|
||||
controller.selectedLocale.value = newValue;
|
||||
final parts = newValue.split('-');
|
||||
if (parts.length == 2) {
|
||||
Get.updateLocale(Locale(parts[0], parts[1]));
|
||||
} else {
|
||||
Get.updateLocale(Locale(newValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)),
|
||||
SizedBox(height: 32),
|
||||
Center(
|
||||
child: GlobalButton(text: "save_changes", onPressed: controller.saveProfile),
|
||||
),
|
||||
],
|
||||
},
|
||||
)),
|
||||
SizedBox(height: 32),
|
||||
Center(
|
||||
child: GlobalButton(text: tr("save_changes"), onPressed: controller.saveProfile),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import "package:get/get.dart";
|
||||
import "package:quiz_app/data/services/connection_service.dart";
|
||||
import "package:quiz_app/data/services/quiz_service.dart";
|
||||
import "package:quiz_app/feature/quiz_creation/controller/quiz_creation_controller.dart";
|
||||
|
||||
|
@ -9,6 +10,7 @@ class QuizCreationBinding extends Bindings {
|
|||
Get.lazyPut<QuizCreationController>(
|
||||
() => QuizCreationController(
|
||||
Get.find<QuizService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,16 +5,22 @@ 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/delete_confirmation.dart';
|
||||
import 'package:quiz_app/component/notification/pop_up_confirmation.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.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/models/base/base_model.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiestion_data_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
|
||||
class QuizCreationController extends GetxController {
|
||||
final QuizService _quizService;
|
||||
|
||||
QuizCreationController(this._quizService);
|
||||
final ConnectionService _connectionService;
|
||||
QuizCreationController(
|
||||
this._quizService,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
final TextEditingController inputSentenceTC = TextEditingController();
|
||||
final TextEditingController questionTC = TextEditingController();
|
||||
|
@ -29,6 +35,8 @@ class QuizCreationController extends GetxController {
|
|||
|
||||
RxInt currentDuration = 30.obs;
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
@ -193,7 +201,7 @@ class QuizCreationController extends GetxController {
|
|||
|
||||
void onBack(BuildContext context) {
|
||||
if (quizData.length <= 1) {
|
||||
Navigator.pop(context);
|
||||
Get.back();
|
||||
} else {
|
||||
AppDialog.showExitConfirmationDialog(context);
|
||||
}
|
||||
|
@ -224,49 +232,77 @@ class QuizCreationController extends GetxController {
|
|||
}
|
||||
|
||||
void generateQuiz() async {
|
||||
CustomFloatingLoading.showLoadingDialog(Get.context!);
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputSentenceTC.text.trim().isEmpty) {
|
||||
CustomNotification.error(title: "Gagal", message: "kalimat atau paragraph tidak boleh kosong");
|
||||
return;
|
||||
}
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
isLoading.value = true;
|
||||
|
||||
try {
|
||||
BaseResponseModel<List<RawQuizModel>> response = await _quizService.createQuizAuto(inputSentenceTC.text);
|
||||
|
||||
if (response.data != null) {
|
||||
final previousLength = quizData.length;
|
||||
if (response.data != null && response.data!.isNotEmpty) {
|
||||
// Check if we should remove the initial empty question
|
||||
bool shouldRemoveInitial = quizData.length == 1 && quizData[0].question == null && quizData[0].answer == null;
|
||||
|
||||
if (previousLength == 1) quizData.removeAt(0);
|
||||
if (shouldRemoveInitial) {
|
||||
quizData.clear();
|
||||
}
|
||||
|
||||
for (final i in response.data!) {
|
||||
// Add new questions
|
||||
for (final quizItem in response.data!) {
|
||||
QuestionType type = QuestionType.fillTheBlank;
|
||||
|
||||
if (i.answer.toString().toLowerCase() == 'true' || i.answer.toString().toLowerCase() == 'false') {
|
||||
if (quizItem.answer.toString().toLowerCase() == 'true' || quizItem.answer.toString().toLowerCase() == 'false') {
|
||||
type = QuestionType.trueOrFalse;
|
||||
}
|
||||
|
||||
quizData.add(QuestionData(
|
||||
index: quizData.length + 1,
|
||||
question: i.qustion,
|
||||
answer: i.answer,
|
||||
question: quizItem.qustion,
|
||||
answer: quizItem.answer,
|
||||
type: type,
|
||||
));
|
||||
}
|
||||
|
||||
if (response.data!.isNotEmpty) {
|
||||
selectedQuizIndex.value = previousLength;
|
||||
// Set the selected index to the first newly added question
|
||||
if (shouldRemoveInitial) {
|
||||
selectedQuizIndex.value = 0;
|
||||
} else {
|
||||
// If we didn't remove initial data, select the first new question
|
||||
selectedQuizIndex.value = quizData.length - response.data!.length;
|
||||
}
|
||||
|
||||
// Update UI with the selected question data
|
||||
if (selectedQuizIndex.value < quizData.length) {
|
||||
final data = quizData[selectedQuizIndex.value];
|
||||
questionTC.text = data.question ?? "";
|
||||
answerTC.text = data.answer ?? "";
|
||||
currentDuration.value = data.duration;
|
||||
currentQuestionType.value = data.type ?? QuestionType.fillTheBlank;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logC.e("Error while generating quiz: $e");
|
||||
CustomFloatingLoading.hideLoading();
|
||||
} finally {
|
||||
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
isGenerate.value = false;
|
||||
inputSentenceTC.text = "";
|
||||
|
||||
if (quizData.isNotEmpty && selectedQuizIndex.value == 0) {
|
||||
final data = quizData[0];
|
||||
if (quizData.isNotEmpty && selectedQuizIndex.value >= quizData.length) {
|
||||
selectedQuizIndex.value = 0;
|
||||
}
|
||||
|
||||
if (quizData.isNotEmpty) {
|
||||
final data = quizData[selectedQuizIndex.value];
|
||||
questionTC.text = data.question ?? "";
|
||||
answerTC.text = data.answer ?? "";
|
||||
currentDuration.value = data.duration;
|
||||
|
@ -274,4 +310,8 @@ class QuizCreationController extends GetxController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
onGoBack(BuildContext context, bool didPop) {
|
||||
if (!isLoading.value) onBack(context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,35 +11,39 @@ class QuizCreationView extends GetView<QuizCreationController> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) => controller.onGoBack(context, didPop),
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
context.tr('create_quiz_title'),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.darkText,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColors.background,
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
context.tr('create_quiz_title'),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.darkText,
|
||||
),
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new_rounded, color: AppColors.darkText),
|
||||
onPressed: () => controller.onBack(context),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new_rounded, color: AppColors.darkText),
|
||||
onPressed: () => controller.onBack(context),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildModeSelector(context),
|
||||
const SizedBox(height: 20),
|
||||
Obx(() => controller.isGenerate.value ? const GenerateComponent() : const CustomQuestionComponent()),
|
||||
],
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildModeSelector(context),
|
||||
const SizedBox(height: 20),
|
||||
Obx(() => controller.isGenerate.value ? const GenerateComponent() : const CustomQuestionComponent()),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/data/services/subject_service.dart';
|
||||
import 'package:quiz_app/feature/quiz_preview/controller/quiz_preview_controller.dart';
|
||||
|
@ -13,6 +14,7 @@ class QuizPreviewBinding extends Bindings {
|
|||
Get.find<QuizService>(),
|
||||
Get.find<UserController>(),
|
||||
Get.find<SubjectService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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/helper/connection_check.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';
|
||||
|
@ -10,6 +11,7 @@ import 'package:quiz_app/data/models/quiz/question_create_request.dart';
|
|||
import 'package:quiz_app/data/models/quiz/question_listings_model.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiestion_data_model.dart';
|
||||
import 'package:quiz_app/data/models/subject/subject_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/data/services/subject_service.dart';
|
||||
|
||||
|
@ -20,11 +22,13 @@ class QuizPreviewController extends GetxController {
|
|||
final QuizService _quizService;
|
||||
final UserController _userController;
|
||||
final SubjectService _subjectService;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
QuizPreviewController(
|
||||
this._quizService,
|
||||
this._userController,
|
||||
this._subjectService,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
RxBool isPublic = false.obs;
|
||||
|
@ -70,6 +74,10 @@ class QuizPreviewController extends GetxController {
|
|||
|
||||
Future<void> onSaveQuiz() async {
|
||||
try {
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
if (isLoading.value) return;
|
||||
|
||||
final title = titleController.text.trim();
|
||||
|
@ -88,11 +96,12 @@ class QuizPreviewController extends GetxController {
|
|||
title: 'Error',
|
||||
message: 'Jumlah soal harus 10 atau lebih',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
CustomFloatingLoading.showLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
|
||||
final now = DateTime.now();
|
||||
final String formattedDate = "${now.day.toString().padLeft(2, '0')}-${now.month.toString().padLeft(2, '0')}-${now.year}";
|
||||
|
@ -116,13 +125,14 @@ class QuizPreviewController extends GetxController {
|
|||
message: 'Kuis berhasil disimpan!',
|
||||
);
|
||||
|
||||
CustomFloatingLoading.hideLoading();
|
||||
Get.offAllNamed(AppRoutes.mainPage, arguments: 2);
|
||||
}
|
||||
} catch (e) {
|
||||
CustomFloatingLoading.hideLoading();
|
||||
logC.e(e);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
// CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,6 +180,10 @@ class QuizPreviewController extends GetxController {
|
|||
subjectIndex.value = index;
|
||||
}
|
||||
|
||||
void onBack() {
|
||||
if (!isLoading.value) Get.back();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
titleController.dispose();
|
||||
|
|
|
@ -34,6 +34,7 @@ class SubjectDropdownComponent extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
},
|
||||
dropdownColor: Colors.white,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
|
|
|
@ -14,13 +14,17 @@ class QuizPreviewPage extends GetView<QuizPreviewController> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: _buildAppBar(context),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: _buildContent(context),
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) => controller.onBack(),
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: _buildAppBar(context),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: _buildContent(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -95,7 +95,7 @@ class QuizResultView extends GetView<QuizResultController> {
|
|||
final parsed = _parseAnswer(question, answer.selectedAnswer);
|
||||
|
||||
return QuizItemWAComponent(
|
||||
index: index,
|
||||
index: index + 1,
|
||||
isCorrect: answer.isCorrect,
|
||||
question: question.question,
|
||||
targetAnswer: parsed.targetAnswer,
|
||||
|
|
|
@ -26,6 +26,8 @@ class RegisterController extends GetxController {
|
|||
var isPasswordHidden = true.obs;
|
||||
var isConfirmPasswordHidden = true.obs;
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
if (!_connectionService.isCurrentlyConnected) {
|
||||
|
@ -81,7 +83,8 @@ class RegisterController extends GetxController {
|
|||
}
|
||||
|
||||
try {
|
||||
CustomFloatingLoading.showLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.showLoading(Get.overlayContext!);
|
||||
isLoading.value = true;
|
||||
await _authService.register(
|
||||
RegisterRequestModel(
|
||||
email: email,
|
||||
|
@ -93,10 +96,12 @@ class RegisterController extends GetxController {
|
|||
);
|
||||
|
||||
Get.back();
|
||||
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
CustomNotification.success(title: "Pendaftaran Berhasil", message: "Akun berhasil dibuat");
|
||||
} catch (e) {
|
||||
CustomFloatingLoading.hideLoadingDialog(Get.context!);
|
||||
CustomFloatingLoading.hideLoading();
|
||||
isLoading.value = false;
|
||||
|
||||
String errorMessage = e.toString().replaceFirst("Exception: ", "");
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/data/controllers/user_controller.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/data/services/session_service.dart';
|
||||
import 'package:quiz_app/data/services/socket_service.dart';
|
||||
|
@ -16,6 +17,7 @@ class RoomMakerBinding extends Bindings {
|
|||
Get.find<UserController>(),
|
||||
Get.find<SocketService>(),
|
||||
Get.find<QuizService>(),
|
||||
Get.find<ConnectionService>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:quiz_app/app/routes/app_pages.dart';
|
||||
import 'package:quiz_app/core/helper/connection_check.dart';
|
||||
import 'package:quiz_app/core/utils/custom_notification.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/base/base_model.dart';
|
||||
|
@ -9,6 +11,7 @@ import 'package:quiz_app/data/models/quiz/quiz_listing_model.dart';
|
|||
import 'package:quiz_app/data/models/session/session_info_model.dart';
|
||||
import 'package:quiz_app/data/models/session/session_request_model.dart';
|
||||
import 'package:quiz_app/data/models/session/session_response_model.dart';
|
||||
import 'package:quiz_app/data/services/connection_service.dart';
|
||||
import 'package:quiz_app/data/services/quiz_service.dart';
|
||||
import 'package:quiz_app/data/services/session_service.dart';
|
||||
import 'package:quiz_app/data/services/socket_service.dart';
|
||||
|
@ -18,12 +21,14 @@ class RoomMakerController extends GetxController {
|
|||
final UserController _userController;
|
||||
final SocketService _socketService;
|
||||
final QuizService _quizService;
|
||||
final ConnectionService _connectionService;
|
||||
|
||||
RoomMakerController(
|
||||
this._sessionService,
|
||||
this._userController,
|
||||
this._socketService,
|
||||
this._quizService,
|
||||
this._connectionService,
|
||||
);
|
||||
|
||||
final selectedQuiz = Rxn<QuizListingModel>();
|
||||
|
@ -47,6 +52,10 @@ class RoomMakerController extends GetxController {
|
|||
}
|
||||
|
||||
Future<void> loadQuiz({bool reset = false}) async {
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
if (isLoading) return;
|
||||
|
||||
isLoading = true;
|
||||
|
@ -92,8 +101,21 @@ class RoomMakerController extends GetxController {
|
|||
}
|
||||
|
||||
void onCreateRoom() async {
|
||||
if (nameTC.text.trim().isEmpty || selectedQuiz.value == null) {
|
||||
Get.snackbar("Gagal", "Nama room dan kuis harus dipilih.");
|
||||
if (nameTC.text.trim().isEmpty || maxPlayerTC.text.trim().isEmpty || selectedQuiz.value == null) {
|
||||
CustomNotification.error(title: "Gagal", message: "Nama room, maksimal pemain dan kuis harus dipilih.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.tryParse(maxPlayerTC.text) == null) {
|
||||
CustomNotification.error(
|
||||
title: "Input tidak valid",
|
||||
message: "Jumlah pemain harus berupa angka tanpa karakter huruf atau simbol.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await _connectionService.isHaveConnection()) {
|
||||
ConnectionNotification.noInternedConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -103,6 +125,7 @@ class RoomMakerController extends GetxController {
|
|||
SessionRequestModel(
|
||||
quizId: quiz.quizId,
|
||||
hostId: _userController.userData!.id,
|
||||
roomName: nameTC.text,
|
||||
limitParticipan: int.parse(maxPlayerTC.text),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -588,52 +588,46 @@ class RoomMakerView extends GetView<RoomMakerController> {
|
|||
}
|
||||
|
||||
Widget _buildCreateRoomButton() {
|
||||
return Obx(() {
|
||||
final canCreate = controller.selectedQuiz.value != null && controller.nameTC.text.isNotEmpty && controller.maxPlayerTC.text.isNotEmpty;
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
width: MediaQuery.of(Get.context!).size.width - 32,
|
||||
height: 56,
|
||||
child: Material(
|
||||
elevation: canCreate ? 8 : 2,
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
width: MediaQuery.of(Get.context!).size.width - 32,
|
||||
height: 56,
|
||||
child: Material(
|
||||
elevation: 8,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: canCreate ? controller.onCreateRoom : null,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: canCreate
|
||||
? LinearGradient(
|
||||
colors: [AppColors.primaryBlue, AppColors.primaryBlue.withValues(alpha: 0.8)],
|
||||
)
|
||||
: null,
|
||||
color: !canCreate ? Colors.grey[300] : null,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: controller.onCreateRoom,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [AppColors.primaryBlue, AppColors.primaryBlue.withValues(alpha: 0.8)],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add_circle,
|
||||
color: canCreate ? Colors.white : Colors.grey[500],
|
||||
size: 24,
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add_circle,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
"Buat Room Sekarang",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
"Buat Room Sekarang",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: canCreate ? Colors.white : Colors.grey[500],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ class WaitingRoomController extends GetxController {
|
|||
WaitingRoomController(this._socketService, this._userController);
|
||||
|
||||
final sessionCode = ''.obs;
|
||||
final roomName = "".obs;
|
||||
String sessionId = '';
|
||||
final quizMeta = Rx<QuizInfo?>(null);
|
||||
final joinedUsers = <UserModel>[].obs;
|
||||
|
@ -42,6 +43,7 @@ class WaitingRoomController extends GetxController {
|
|||
sessionId = roomData!.sessionId;
|
||||
|
||||
quizMeta.value = data.quizInfo;
|
||||
roomName.value = data.sessionInfo.roomName;
|
||||
|
||||
joinedUsers.assignAll(data.sessionInfo.participants);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:quiz_app/app/const/text/string_extension.dart';
|
||||
import 'package:quiz_app/app/const/text/text_style.dart';
|
||||
import 'package:quiz_app/component/global_button.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiz_info_model.dart';
|
||||
import 'package:quiz_app/data/models/user/user_model.dart';
|
||||
|
@ -11,7 +14,9 @@ class WaitingRoomView extends GetView<WaitingRoomController> {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(title: const Text("Waiting Room")),
|
||||
appBar: AppBar(
|
||||
title: Text(tr("waiting_room.title"), style: AppTextStyles.title),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Obx(() {
|
||||
|
@ -22,25 +27,39 @@ class WaitingRoomView extends GetView<WaitingRoomController> {
|
|||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
Center(
|
||||
child: Obx(() => Text(
|
||||
controller.roomName.value.toTitleCase(),
|
||||
style: AppTextStyles.title,
|
||||
)),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildQuizMeta(quiz!),
|
||||
const SizedBox(height: 20),
|
||||
_buildSessionCode(context, session),
|
||||
const SizedBox(height: 20),
|
||||
const Text("Peserta yang Bergabung:", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
Text(
|
||||
tr("waiting_room.participants_joined"),
|
||||
style: AppTextStyles.subtitle.copyWith(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.darkText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(child: Obx(() => _buildUserList(users.toList()))),
|
||||
const SizedBox(height: 16),
|
||||
if (controller.isAdmin.value)
|
||||
GlobalButton(
|
||||
text: "Mulai Kuis",
|
||||
onPressed: controller.startQuiz,
|
||||
)
|
||||
else
|
||||
GlobalButton(
|
||||
text: "Tinggalkan Ruangan",
|
||||
onPressed: controller.leaveRoom,
|
||||
baseColor: const Color.fromARGB(255, 204, 14, 0),
|
||||
)
|
||||
controller.isAdmin.value
|
||||
? GlobalButton(
|
||||
text: tr("start_quiz"),
|
||||
onPressed: controller.startQuiz,
|
||||
)
|
||||
: GlobalButton(
|
||||
text: tr("waiting_room.leave_room"),
|
||||
onPressed: controller.leaveRoom,
|
||||
baseColor: const Color.fromARGB(255, 204, 14, 0),
|
||||
)
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
@ -52,18 +71,19 @@ class WaitingRoomView extends GetView<WaitingRoomController> {
|
|||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryBlue.withValues(alpha: 0.05),
|
||||
color: AppColors.accentBlue.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.primaryBlue),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text("Session Code: ", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
SelectableText(code, style: const TextStyle(fontSize: 16)),
|
||||
Text(tr("waiting_room.session_code"), style: AppTextStyles.statValue),
|
||||
const SizedBox(width: 4),
|
||||
SelectableText(code, style: AppTextStyles.body.copyWith(fontSize: 16)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
tooltip: 'Salin Kode',
|
||||
tooltip: tr("waiting_room.copy_code"),
|
||||
onPressed: () => controller.copySessionCode(context),
|
||||
),
|
||||
],
|
||||
|
@ -72,7 +92,6 @@ class WaitingRoomView extends GetView<WaitingRoomController> {
|
|||
}
|
||||
|
||||
Widget _buildQuizMeta(QuizInfo quiz) {
|
||||
// if (quiz == null) return const SizedBox.shrink();
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
width: double.infinity,
|
||||
|
@ -84,12 +103,12 @@ class WaitingRoomView extends GetView<WaitingRoomController> {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text("Informasi Kuis:", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
Text(tr("waiting_room.quiz_info"), style: AppTextStyles.subtitle.copyWith(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 8),
|
||||
Text("Judul: ${quiz.title}"),
|
||||
Text("Deskripsi: ${quiz.description}"),
|
||||
Text("Jumlah Soal: ${quiz.totalQuiz}"),
|
||||
Text("Durasi: ${quiz.limitDuration ~/ 60} menit"),
|
||||
Text("${tr("waiting_room.quiz_title")}: ${quiz.title}", style: AppTextStyles.body),
|
||||
Text("${tr("waiting_room.quiz_description")}: ${quiz.description}", style: AppTextStyles.body),
|
||||
Text("${tr("waiting_room.quiz_total_question")}: ${quiz.totalQuiz}", style: AppTextStyles.body),
|
||||
Text("${tr("waiting_room.quiz_duration")}: ${quiz.limitDuration ~/ 60} min", style: AppTextStyles.body),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -110,9 +129,9 @@ class WaitingRoomView extends GetView<WaitingRoomController> {
|
|||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(child: Text(user.username[0])),
|
||||
CircleAvatar(child: Text(user.username[0].toUpperCase())),
|
||||
const SizedBox(width: 12),
|
||||
Text(user.username, style: const TextStyle(fontSize: 16)),
|
||||
Text(user.username, style: AppTextStyles.body.copyWith(fontSize: 16)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
@ -29,7 +29,8 @@ void main() {
|
|||
Locale('ms', 'MY'),
|
||||
],
|
||||
path: 'assets/translations',
|
||||
fallbackLocale: Locale('en', 'US'),
|
||||
fallbackLocale: Locale('id', 'ID'),
|
||||
startLocale: Locale('id', 'ID'),
|
||||
useOnlyLangCode: false,
|
||||
child: MyApp(),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue