fix: logic on the interface greating time for user

This commit is contained in:
akhdanre 2025-05-25 16:03:52 +07:00
parent c84133a372
commit 661930d2bd
8 changed files with 88 additions and 29 deletions

View File

@ -1,5 +1,11 @@
{
"greeting_time": "Good Afternoon",
"greeting_time": {
"morning": "Good Morning",
"afternoon": "Good Afternoon",
"evening": "Good Evening",
"night": "Good Night"
},
"greeting_user": "Hello {user}",
"create_room": "Create Room",
"join_room": "Join Room",
@ -106,10 +112,28 @@
"close": "Close",
"your_answer": "Your answer: {answer}",
"correct": "Correct",
"correct_answer": "Correct answer: {answer}",
"not_answered": "Not Answered",
"seconds_suffix": "s",
"quiz_type_option": "Multiple Choice",
"quiz_type_true_false": "True or False",
"quiz_type_fill_the_blank": "Fill in the Blank"
"quiz_type_fill_the_blank": "Fill in the Blank",
"quiz_detail_title": "Quiz Detail",
"question_label": "Question",
"duration_label": "Duration",
"minutes_suffix": "minutes",
"start_quiz": "Start Quiz",
"duration": {
"second": "{} second",
"minute": "{} minute",
"hour": "{} hour"
},
"duration_suffix": {
"second": "{} s",
"minute": "{} m",
"hour": "{} h"
}
}

View File

@ -1,5 +1,11 @@
{
"greeting_time": "Selamat Siang",
"greeting_time": {
"morning": "Selamat Pagi",
"afternoon": "Selamat Siang",
"evening": "Selamat Sore",
"night": "Selamat Malam"
},
"greeting_user": "Halo {user}",
"create_room": "Buat Ruangan",
"join_room": "Gabung Ruang",

View File

@ -231,6 +231,7 @@ class _AnswerIndicator extends StatelessWidget {
child: Text(
// "Jawaban benar: <answer>"
tr('correct_answer', namedArgs: {'answer': correctAnswerText}),
style: AppTextStyles.caption,
softWrap: true,
),

View File

@ -17,9 +17,9 @@ class DetailQuizView extends GetView<DetailQuizController> {
appBar: AppBar(
backgroundColor: AppColors.background,
elevation: 0,
title: const Text(
'Detail Quiz',
style: TextStyle(
title: Text(
tr('quiz_detail_title'),
style: const TextStyle(
color: AppColors.darkText,
fontWeight: FontWeight.bold,
),
@ -32,7 +32,7 @@ class DetailQuizView extends GetView<DetailQuizController> {
padding: const EdgeInsets.all(20),
child: Obx(
() => controller.isLoading.value
? Center(child: LoadingWidget())
? const Center(child: LoadingWidget())
: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -67,19 +67,16 @@ class DetailQuizView extends GetView<DetailQuizController> {
const Icon(Icons.timer_rounded, size: 16, color: AppColors.softGrayText),
const SizedBox(width: 6),
Text(
'${controller.data.limitDuration ~/ 60} menit',
'${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),
GlobalButton(text: "Kerjakan", onPressed: controller.goToPlayPage),
const SizedBox(height: 20),
// GlobalButton(text: "buat ruangan", onPressed: () {}),
const SizedBox(height: 20),
const Divider(thickness: 1.2, color: AppColors.borderLight),
const SizedBox(height: 20),
@ -113,7 +110,7 @@ class DetailQuizView extends GetView<DetailQuizController> {
border: Border.all(color: AppColors.borderLight),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
color: Colors.black.withOpacity(0.05),
blurRadius: 6,
offset: const Offset(2, 2),
),
@ -123,7 +120,7 @@ class DetailQuizView extends GetView<DetailQuizController> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Soal $index',
'${tr('question_label')} $index',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
@ -147,17 +144,9 @@ class DetailQuizView extends GetView<DetailQuizController> {
color: AppColors.darkText,
),
),
// const SizedBox(height: 12),
// Text(
// 'Jawaban: ${question.targetAnswer}',
// style: const TextStyle(
// fontSize: 14,
// color: AppColors.softGrayText,
// ),
// ),
const SizedBox(height: 8),
Text(
'Durasi: ${question.duration} detik',
'${tr('duration_label')}: ${question.duration} ${tr('seconds_suffix')}',
style: const TextStyle(
fontSize: 12,
color: AppColors.softGrayText,

View File

@ -107,7 +107,7 @@ class DetailHistoryView extends GetView<DetailHistoryController> {
children: [
_buildStatItem(
icon: LucideIcons.checkCircle2,
label: context.tr('correct_answer'),
label: tr('correct'),
value: "${quiz.totalCorrect}/${quiz.questionListings.length}",
color: Colors.green,
),

View File

@ -21,6 +21,8 @@ class HomeController extends GetxController {
this._subjectService,
);
RxInt timeStatus = 1.obs;
Rx<String> get userName => _userController.userName;
Rx<String?> get userImage => _userController.userImage;
@ -31,6 +33,7 @@ class HomeController extends GetxController {
@override
void onInit() {
_getRecomendationQuiz();
_getGreetingStatusByTime();
loadSubjectData();
super.onInit();
}
@ -68,4 +71,18 @@ class HomeController extends GetxController {
AppRoutes.listingQuizPage,
arguments: {"page": page, "id": subjectId, "subject_name": subjecName},
);
void _getGreetingStatusByTime() {
final hour = DateTime.now().hour;
if (hour >= 5 && hour < 12) {
timeStatus.value = 1;
} else if (hour >= 12 && hour < 15) {
timeStatus.value = 2;
} else if (hour >= 15 && hour < 18) {
timeStatus.value = 3;
} else {
timeStatus.value = 4;
}
}
}

View File

@ -4,7 +4,13 @@ import 'package:flutter/material.dart';
class UserGretingsComponent extends StatelessWidget {
final String userName;
final String? userImage;
const UserGretingsComponent({super.key, required this.userName, required this.userImage});
final int greatingStatus;
const UserGretingsComponent({
super.key,
required this.userName,
required this.userImage,
required this.greatingStatus,
});
@override
Widget build(BuildContext context) {
@ -35,11 +41,11 @@ class UserGretingsComponent extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.tr("greeting_time"),
style: TextStyle(fontWeight: FontWeight.bold),
tr(_getGreetingKey(greatingStatus)),
style: const TextStyle(fontWeight: FontWeight.bold),
),
Text(
context.tr("greeting_user", namedArgs: {"user": userName}),
tr("greeting_user", namedArgs: {"user": userName}),
style: TextStyle(fontWeight: FontWeight.w500),
),
],
@ -52,4 +58,19 @@ class UserGretingsComponent extends StatelessWidget {
],
);
}
String _getGreetingKey(int status) {
switch (status) {
case 1:
return 'greeting_time.morning';
case 2:
return 'greeting_time.afternoon';
case 3:
return 'greeting_time.evening';
case 4:
return 'greeting_time.night';
default:
return 'greeting_time.morning'; // fallback
}
}
}

View File

@ -27,6 +27,7 @@ class HomeView extends GetView<HomeController> {
() => UserGretingsComponent(
userName: controller.userName.value,
userImage: controller.userImage.value,
greatingStatus: controller.timeStatus.value,
),
),
const SizedBox(height: 20),