From d69ebca9c7b43905a8895aed3e94f2a04b5f93c3 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Thu, 20 Mar 2025 11:51:05 +0800 Subject: [PATCH] =?UTF-8?q?editProfile=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/profile_controller.dart | 12 ++ lib/modules/profile/views/profile_view.dart | 113 +++++++++++------- lib/modules/settings/views/settings_view.dart | 2 +- 3 files changed, 84 insertions(+), 43 deletions(-) diff --git a/lib/modules/profile/controllers/profile_controller.dart b/lib/modules/profile/controllers/profile_controller.dart index 837a59b64..a75f87ee9 100644 --- a/lib/modules/profile/controllers/profile_controller.dart +++ b/lib/modules/profile/controllers/profile_controller.dart @@ -3,6 +3,7 @@ import 'package:get_storage/get_storage.dart'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; import '../../../data/models/user_model.dart'; +import '../../settings/controllers/settings_controller.dart'; class ProfileController extends GetxController { static ProfileController get to => Get.find(); @@ -133,6 +134,11 @@ class ProfileController extends GetxController { } }); await saveUserInfo(); + + // 通知 SettingsController 更新 + if (Get.isRegistered()) { + Get.find().loadUserInfo(); + } } } @@ -144,6 +150,12 @@ class ProfileController extends GetxController { } }); await saveUserInfo(); + + // 同步更新 SettingsController + if (Get.isRegistered()) { + final settingsController = Get.find(); + settingsController.loadUserInfo(); + } } } } \ No newline at end of file diff --git a/lib/modules/profile/views/profile_view.dart b/lib/modules/profile/views/profile_view.dart index c23bf2685..dd21ed8bc 100644 --- a/lib/modules/profile/views/profile_view.dart +++ b/lib/modules/profile/views/profile_view.dart @@ -63,7 +63,6 @@ class ProfileView extends GetView { body: ListView( children: [ SizedBox(height: 12.h), - const Divider(), _buildMenuItem( title: '关于'.tr, @@ -72,7 +71,6 @@ class ProfileView extends GetView { // TODO: 实现关于页面 }, ), - const Divider(), _buildMenuItem( title: '火山语音合成测试'.tr, @@ -82,8 +80,6 @@ class ProfileView extends GetView { Get.toNamed(Routes.TTS_TEST); }, ), - - const Divider(), _buildMenuItem( title: '火山语音识别测试'.tr, @@ -102,7 +98,7 @@ class ProfileView extends GetView { Get.toNamed(Routes.AZURE_ASR_TEST); }, ), - const Divider(), + const Divider(), _buildMenuItem( title: 'Azure语音合成测试'.tr, icon: Icons.record_voice_over, @@ -134,8 +130,7 @@ class ProfileView extends GetView { bottomNavigationBar: const CommonBottomNav(currentIndex: 2), ); } -} - +} // EditProfileView: 编辑个人资料页面 class EditProfileView extends GetView { @@ -144,29 +139,45 @@ class EditProfileView extends GetView { @override Widget build(BuildContext context) { final isDarkMode = Theme.of(context).brightness == Brightness.dark; - final nameController = TextEditingController(text: controller.userInfo.value.name); - + final nameController = + TextEditingController(text: controller.userInfo.value.name); + return Scaffold( appBar: AppBar( - title: const Text('个人资料'), - actions: [ - TextButton( - onPressed: () { - // 保存用户名 - controller.updateUserName(nameController.text); - // 返回上一级页面 - Get.back(); - }, - child: Text( - '保存', - style: TextStyle( - fontSize: 16.sp, - color: isDarkMode ? Colors.blue[300] : Colors.blue, - fontWeight: FontWeight.w500, - ), - ), + automaticallyImplyLeading: false, + centerTitle: true, + elevation: 0, + backgroundColor: isDarkMode ? Colors.black : Colors.white, + title: Text( + '编辑个人资料', + style: TextStyle( + fontSize: 17.sp, + fontWeight: FontWeight.w600, + color: isDarkMode ? Colors.white : Colors.black, ), - ], + ), + // actions: [ + // TextButton( + // onPressed: () { + // // 保存用户名 + // controller.updateUserName(nameController.text); + // // 返回上一级页面 + // Get.back(); + // }, + // style: TextButton.styleFrom( + // foregroundColor: Colors.blue, // 确保按钮文字颜色 + // padding: EdgeInsets.symmetric(horizontal: 16.w), + // ), + // child: Text( + // '保 存', + // style: TextStyle( + // fontSize: 16.sp, + // color: isDarkMode ? Colors.blue[300] : Colors.blue, + // fontWeight: FontWeight.w500, + // ), + // ), + // ), + // ], ), body: Padding( padding: EdgeInsets.all(16.w), @@ -175,22 +186,40 @@ class EditProfileView extends GetView { // 头像编辑 Center( child: GestureDetector( - onTap: () => controller.updateUserAvatar(), - child: Obx(() => CircleAvatar( - radius: 50.r, - backgroundImage: controller.userInfo.value.avatar.isNotEmpty - ? FileImage(File(controller.userInfo.value.avatar)) - : null, - child: controller.userInfo.value.avatar.isEmpty - ? Icon(Icons.person, size: 50.r) - : null, - // onBackgroundImageError: hasAvatar - // ? (_, __) {} - // : null, - )), - ), + onTap: () => controller.updateUserAvatar(), + child: Stack( + children: [ + Obx(() => CircleAvatar( + radius: 50.r, + backgroundImage: + controller.userInfo.value.avatar.isNotEmpty + ? FileImage( + File(controller.userInfo.value.avatar)) + : null, + child: controller.userInfo.value.avatar.isEmpty + ? Icon(Icons.person, size: 50.r) + : null, + )), + Positioned( + right: 0, + bottom: 0, + child: Container( + padding: EdgeInsets.all(4.w), + decoration: const BoxDecoration( + color: Colors.blue, + shape: BoxShape.circle, + ), + child: Icon( + Icons.camera_alt, + size: 20.w, + color: Colors.white, + )), + ) + ], + )), ), SizedBox(height: 20.h), + // 昵称编辑 - 使用外部定义的controller而不是每次重建 TextField( controller: nameController, @@ -200,7 +229,7 @@ class EditProfileView extends GetView { ), ), // ... 其他编辑项 ... - + SizedBox(height: 30.h), // 添加一个大的保存按钮 SizedBox( diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index 126ab3ab5..d60967e6d 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -82,7 +82,7 @@ class SettingsView extends GetView { child: Row( children: [ Obx(()=>GestureDetector( - onTap: ()=>controller.updateUserAvatar(), + //onTap: ()=>controller.updateUserAvatar(), child:Container(//用户头像部分 width: 60.w, height: 60.w,