Browse Source

editProfile优化

weicu
lxm 2 years ago
parent
commit
d69ebca9c7
  1. 12
      lib/modules/profile/controllers/profile_controller.dart
  2. 85
      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: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<SettingsController>()) {
Get.find<SettingsController>().loadUserInfo();
}
}
}
@ -144,6 +150,12 @@ class ProfileController extends GetxController {
}
});
await saveUserInfo();
// 同步更新 SettingsController
if (Get.isRegistered<SettingsController>()) {
final settingsController = Get.find<SettingsController>();
settingsController.loadUserInfo();
}
}
}
}

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

@ -63,7 +63,6 @@ class ProfileView extends GetView<ProfileController> {
body: ListView(
children: [
SizedBox(height: 12.h),
const Divider(),
_buildMenuItem(
title: '关于'.tr,
@ -72,7 +71,6 @@ class ProfileView extends GetView<ProfileController> {
// TODO: 实现关于页面
},
),
const Divider(),
_buildMenuItem(
title: '火山语音合成测试'.tr,
@ -82,8 +80,6 @@ class ProfileView extends GetView<ProfileController> {
Get.toNamed(Routes.TTS_TEST);
},
),
const Divider(),
_buildMenuItem(
title: '火山语音识别测试'.tr,
@ -136,7 +132,6 @@ class ProfileView extends GetView<ProfileController> {
}
}
// EditProfileView: 编辑个人资料页面
class EditProfileView extends GetView<ProfileController> {
const EditProfileView({Key? key}) : super(key: key);
@ -144,29 +139,45 @@ class EditProfileView extends GetView<ProfileController> {
@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(
'保存',
automaticallyImplyLeading: false,
centerTitle: true,
elevation: 0,
backgroundColor: isDarkMode ? Colors.black : Colors.white,
title: Text(
'编辑个人资料',
style: TextStyle(
fontSize: 16.sp,
color: isDarkMode ? Colors.blue[300] : Colors.blue,
fontWeight: FontWeight.w500,
),
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),
@ -176,21 +187,39 @@ class EditProfileView extends GetView<ProfileController> {
Center(
child: GestureDetector(
onTap: () => controller.updateUserAvatar(),
child: Obx(() => CircleAvatar(
child: Stack(
children: [
Obx(() => CircleAvatar(
radius: 50.r,
backgroundImage: controller.userInfo.value.avatar.isNotEmpty
? FileImage(File(controller.userInfo.value.avatar))
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,
)),
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,

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

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

Loading…
Cancel
Save