From 60091b8031a4a7f0fe291b277ed7647795bc62b0 Mon Sep 17 00:00:00 2001 From: akhdanre Date: Sun, 18 May 2025 15:36:39 +0700 Subject: [PATCH] feat: done create update profile interface --- lib/app/routes/app_pages.dart | 7 ++ lib/app/routes/app_routes.dart | 2 + lib/component/global_dropdown_field.dart | 37 +++++++++++ .../binding/update_profile_binding.dart | 9 +++ .../controller/profile_controller.dart | 2 +- .../controller/update_profile_controller.dart | 20 ++++++ .../profile/view/update_profile_view.dart | 66 +++++++++++++++++++ 7 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 lib/component/global_dropdown_field.dart create mode 100644 lib/feature/profile/binding/update_profile_binding.dart create mode 100644 lib/feature/profile/controller/update_profile_controller.dart create mode 100644 lib/feature/profile/view/update_profile_view.dart diff --git a/lib/app/routes/app_pages.dart b/lib/app/routes/app_pages.dart index 692f6e5..773afc9 100644 --- a/lib/app/routes/app_pages.dart +++ b/lib/app/routes/app_pages.dart @@ -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(), diff --git a/lib/app/routes/app_routes.dart b/lib/app/routes/app_routes.dart index 3410b5d..49ebba5 100644 --- a/lib/app/routes/app_routes.dart +++ b/lib/app/routes/app_routes.dart @@ -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"; } diff --git a/lib/component/global_dropdown_field.dart b/lib/component/global_dropdown_field.dart new file mode 100644 index 0000000..9802887 --- /dev/null +++ b/lib/component/global_dropdown_field.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; + +class GlobalDropdownField extends StatelessWidget { + final T value; + final List> items; + final ValueChanged 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( + value: value, + isExpanded: true, + onChanged: onChanged, + items: items, + ), + ), + ); + } +} diff --git a/lib/feature/profile/binding/update_profile_binding.dart b/lib/feature/profile/binding/update_profile_binding.dart new file mode 100644 index 0000000..505a59d --- /dev/null +++ b/lib/feature/profile/binding/update_profile_binding.dart @@ -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()); + } +} diff --git a/lib/feature/profile/controller/profile_controller.dart b/lib/feature/profile/controller/profile_controller.dart index 3fe93d7..7e7d088 100644 --- a/lib/feature/profile/controller/profile_controller.dart +++ b/lib/feature/profile/controller/profile_controller.dart @@ -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 { diff --git a/lib/feature/profile/controller/update_profile_controller.dart b/lib/feature/profile/controller/update_profile_controller.dart new file mode 100644 index 0000000..2684083 --- /dev/null +++ b/lib/feature/profile/controller/update_profile_controller.dart @@ -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 localeMap = { + 'English': 'en-US', + 'Indonesian': 'id-ID', + 'French': 'fr-FR', + 'Spanish': 'es-ES', + }; + void saveProfile() { + Get.snackbar('Success', 'Profile updated successfully'); + } +} diff --git a/lib/feature/profile/view/update_profile_view.dart b/lib/feature/profile/view/update_profile_view.dart new file mode 100644 index 0000000..3bb4404 --- /dev/null +++ b/lib/feature/profile/view/update_profile_view.dart @@ -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 { + @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( + value: controller.selectedLocale.value, + items: controller.localeMap.entries.map>((entry) { + return DropdownMenuItem( + 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), + ), + ], + ), + ), + ); + } +}