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