feat: done create update profile interface

This commit is contained in:
akhdanre 2025-05-18 15:36:39 +07:00
parent d925a22bb0
commit 60091b8031
7 changed files with 142 additions and 1 deletions

View File

@ -21,6 +21,8 @@ import 'package:quiz_app/feature/navigation/views/navbar_view.dart';
import 'package:quiz_app/feature/play_quiz_multiplayer/binding/play_quiz_multiplayer_binding.dart';
import 'package:quiz_app/feature/play_quiz_multiplayer/view/play_quiz_multiplayer.dart';
import 'package:quiz_app/feature/profile/binding/profile_binding.dart';
import 'package:quiz_app/feature/profile/binding/update_profile_binding.dart';
import 'package:quiz_app/feature/profile/view/update_profile_view.dart';
import 'package:quiz_app/feature/quiz_creation/binding/quiz_creation_binding.dart';
import 'package:quiz_app/feature/quiz_creation/view/quiz_creation_view.dart';
import 'package:quiz_app/feature/quiz_play/binding/quiz_play_binding.dart';
@ -135,6 +137,11 @@ class AppPages {
page: () => PlayQuizMultiplayerView(),
binding: PlayQuizMultiplayerBinding(),
),
GetPage(
name: AppRoutes.updateProfilePage,
page: () => UpdateProfilePage(),
binding: UpdateProfileBinding(),
),
// GetPage(
// name: AppRoutes.monitorResultMPLPage,
// page: () => AdminResultPage(),

View File

@ -25,4 +25,6 @@ abstract class AppRoutes {
static const playQuizMPLPage = "/room/quiz/play";
static const monitorQuizMPLPage = "/room/quiz/monitor";
static const monitorResultMPLPage = "/room/quiz/monitor/result";
static const updateProfilePage = "/profile/update";
}

View File

@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
class GlobalDropdownField<T> extends StatelessWidget {
final T value;
final List<DropdownMenuItem<T>> items;
final ValueChanged<T?> onChanged;
const GlobalDropdownField({
super.key,
required this.value,
required this.items,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
decoration: BoxDecoration(
color: const Color.fromARGB(255, 234, 234, 235),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: const Color(0xFF0052CC),
width: 1.5,
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<T>(
value: value,
isExpanded: true,
onChanged: onChanged,
items: items,
),
),
);
}
}

View File

@ -0,0 +1,9 @@
import 'package:get/get.dart';
import 'package:quiz_app/feature/profile/controller/update_profile_controller.dart';
class UpdateProfileBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => UpdateProfileController());
}
}

View File

@ -39,7 +39,7 @@ class ProfileController extends GetxController {
}
void editProfile() {
logC.i("Edit profile pressed");
Get.toNamed(AppRoutes.updateProfilePage);
}
void changeLanguage(BuildContext context, String languageCode, String countryCode) async {

View File

@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class UpdateProfileController extends GetxController {
final nameController = TextEditingController();
final phoneController = TextEditingController();
final birthDateController = TextEditingController();
var selectedLocale = 'en-US'.obs;
final Map<String, String> localeMap = {
'English': 'en-US',
'Indonesian': 'id-ID',
'French': 'fr-FR',
'Spanish': 'es-ES',
};
void saveProfile() {
Get.snackbar('Success', 'Profile updated successfully');
}
}

View File

@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:quiz_app/component/global_button.dart';
import 'package:quiz_app/component/global_dropdown_field.dart';
import 'package:quiz_app/component/global_text_field.dart';
import 'package:quiz_app/component/label_text_field.dart';
import 'package:quiz_app/feature/profile/controller/update_profile_controller.dart';
class UpdateProfilePage extends GetView<UpdateProfileController> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Update Profile'),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: [
LabelTextField(label: "Name"),
GlobalTextField(controller: controller.nameController),
SizedBox(height: 16),
LabelTextField(label: "Phone"),
GlobalTextField(
controller: controller.phoneController,
hintText: 'Enter your phone number',
),
SizedBox(height: 16),
LabelTextField(label: "Birth Date"),
GlobalTextField(
controller: controller.birthDateController,
hintText: 'Enter your birth date',
),
SizedBox(height: 16),
LabelTextField(label: "Locale"),
Obx(() => GlobalDropdownField<String>(
value: controller.selectedLocale.value,
items: controller.localeMap.entries.map<DropdownMenuItem<String>>((entry) {
return DropdownMenuItem<String>(
value: entry.value,
child: Text(entry.key), // Display country name
);
}).toList(),
onChanged: (String? newValue) {
if (newValue != null) {
controller.selectedLocale.value = newValue;
final parts = newValue.split('-');
if (parts.length == 2) {
Get.updateLocale(Locale(parts[0], parts[1]));
} else {
Get.updateLocale(Locale(newValue));
}
}
},
)),
SizedBox(height: 32),
Center(
child: GlobalButton(text: "save_changes", onPressed: controller.saveProfile),
),
],
),
),
);
}
}