Browse Source

editProfile优化

weicu
lxm 2 years ago
parent
commit
d69ebca9c7
  1. 12
      lib/modules/profile/controllers/profile_controller.dart
  2. 113
      lib/modules/profile/views/profile_view.dart
  3. 2
      lib/modules/settings/views/settings_view.dart

12
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:flutter/material.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import '../../../data/models/user_model.dart'; import '../../../data/models/user_model.dart';
import '../../settings/controllers/settings_controller.dart';
class ProfileController extends GetxController { class ProfileController extends GetxController {
static ProfileController get to => Get.find(); static ProfileController get to => Get.find();
@ -133,6 +134,11 @@ class ProfileController extends GetxController {
} }
}); });
await saveUserInfo(); await saveUserInfo();
// 通知 SettingsController 更新
if (Get.isRegistered<SettingsController>()) {
Get.find<SettingsController>().loadUserInfo();
}
} }
} }
@ -144,6 +150,12 @@ class ProfileController extends GetxController {
} }
}); });
await saveUserInfo(); await saveUserInfo();
// 同步更新 SettingsController
if (Get.isRegistered<SettingsController>()) {
final settingsController = Get.find<SettingsController>();
settingsController.loadUserInfo();
}
} }
} }
} }

113
lib/modules/profile/views/profile_view.dart

@ -63,7 +63,6 @@ class ProfileView extends GetView<ProfileController> {
body: ListView( body: ListView(
children: [ children: [
SizedBox(height: 12.h), SizedBox(height: 12.h),
const Divider(), const Divider(),
_buildMenuItem( _buildMenuItem(
title: '关于'.tr, title: '关于'.tr,
@ -72,7 +71,6 @@ class ProfileView extends GetView<ProfileController> {
// TODO: 实现关于页面 // TODO: 实现关于页面
}, },
), ),
const Divider(), const Divider(),
_buildMenuItem( _buildMenuItem(
title: '火山语音合成测试'.tr, title: '火山语音合成测试'.tr,
@ -82,8 +80,6 @@ class ProfileView extends GetView<ProfileController> {
Get.toNamed(Routes.TTS_TEST); Get.toNamed(Routes.TTS_TEST);
}, },
), ),
const Divider(), const Divider(),
_buildMenuItem( _buildMenuItem(
title: '火山语音识别测试'.tr, title: '火山语音识别测试'.tr,
@ -102,7 +98,7 @@ class ProfileView extends GetView<ProfileController> {
Get.toNamed(Routes.AZURE_ASR_TEST); Get.toNamed(Routes.AZURE_ASR_TEST);
}, },
), ),
const Divider(), const Divider(),
_buildMenuItem( _buildMenuItem(
title: 'Azure语音合成测试'.tr, title: 'Azure语音合成测试'.tr,
icon: Icons.record_voice_over, icon: Icons.record_voice_over,
@ -134,8 +130,7 @@ class ProfileView extends GetView<ProfileController> {
bottomNavigationBar: const CommonBottomNav(currentIndex: 2), bottomNavigationBar: const CommonBottomNav(currentIndex: 2),
); );
} }
} }
// EditProfileView: 编辑个人资料页面 // EditProfileView: 编辑个人资料页面
class EditProfileView extends GetView<ProfileController> { class EditProfileView extends GetView<ProfileController> {
@ -144,29 +139,45 @@ class EditProfileView extends GetView<ProfileController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark; 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( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('个人资料'), automaticallyImplyLeading: false,
actions: [ centerTitle: true,
TextButton( elevation: 0,
onPressed: () { backgroundColor: isDarkMode ? Colors.black : Colors.white,
// 保存用户名 title: Text(
controller.updateUserName(nameController.text); '编辑个人资料',
// 返回上一级页面 style: TextStyle(
Get.back(); fontSize: 17.sp,
}, fontWeight: FontWeight.w600,
child: Text( color: isDarkMode ? Colors.white : Colors.black,
'保存',
style: TextStyle(
fontSize: 16.sp,
color: isDarkMode ? Colors.blue[300] : Colors.blue,
fontWeight: FontWeight.w500,
),
),
), ),
], ),
// 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( body: Padding(
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
@ -175,22 +186,40 @@ class EditProfileView extends GetView<ProfileController> {
// 头像编辑 // 头像编辑
Center( Center(
child: GestureDetector( child: GestureDetector(
onTap: () => controller.updateUserAvatar(), onTap: () => controller.updateUserAvatar(),
child: Obx(() => CircleAvatar( child: Stack(
radius: 50.r, children: [
backgroundImage: controller.userInfo.value.avatar.isNotEmpty Obx(() => CircleAvatar(
? FileImage(File(controller.userInfo.value.avatar)) radius: 50.r,
: null, backgroundImage:
child: controller.userInfo.value.avatar.isEmpty controller.userInfo.value.avatar.isNotEmpty
? Icon(Icons.person, size: 50.r) ? FileImage(
: null, File(controller.userInfo.value.avatar))
// onBackgroundImageError: hasAvatar : null,
// ? (_, __) {} child: controller.userInfo.value.avatar.isEmpty
// : null, ? 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), SizedBox(height: 20.h),
// 昵称编辑 - 使用外部定义的controller而不是每次重建 // 昵称编辑 - 使用外部定义的controller而不是每次重建
TextField( TextField(
controller: nameController, controller: nameController,
@ -200,7 +229,7 @@ class EditProfileView extends GetView<ProfileController> {
), ),
), ),
// ... 其他编辑项 ... // ... 其他编辑项 ...
SizedBox(height: 30.h), SizedBox(height: 30.h),
// 添加一个大的保存按钮 // 添加一个大的保存按钮
SizedBox( SizedBox(

2
lib/modules/settings/views/settings_view.dart

@ -82,7 +82,7 @@ class SettingsView extends GetView<SettingsController> {
child: Row( child: Row(
children: [ children: [
Obx(()=>GestureDetector( Obx(()=>GestureDetector(
onTap: ()=>controller.updateUserAvatar(), //onTap: ()=>controller.updateUserAvatar(),
child:Container(//用户头像部分 child:Container(//用户头像部分
width: 60.w, width: 60.w,
height: 60.w, height: 60.w,

Loading…
Cancel
Save