You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
450 lines
12 KiB
450 lines
12 KiB
import 'package:dating_touchme_app/extension/ex_widget.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../controller/message/chat_settings_controller.dart';
|
|
import '../../generated/assets.dart';
|
|
import '../../model/home/marriage_data.dart';
|
|
|
|
class ChatSettingsPage extends StatelessWidget {
|
|
final String userId;
|
|
final MarriageData? userData;
|
|
|
|
const ChatSettingsPage({
|
|
required this.userId,
|
|
this.userData,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// 验证参数
|
|
if (userId.isEmpty) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('聊天设置'),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios),
|
|
onPressed: () => Get.back(),
|
|
),
|
|
),
|
|
body: const Center(
|
|
child: Text('用户ID无效'),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 初始化控制器,传递用户信息
|
|
// 使用 init 参数确保控制器在 GetBuilder 之前初始化
|
|
return GetBuilder<ChatSettingsController>(
|
|
init: ChatSettingsController(
|
|
userId: userId,
|
|
userData: userData,
|
|
),
|
|
builder: (controller) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: AppBar(
|
|
title: Text(
|
|
'聊天设置',
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
centerTitle: true,
|
|
backgroundColor: Colors.white,
|
|
elevation: 0,
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back_ios, color: Colors.black, size: 20.w),
|
|
onPressed: () => Get.back(),
|
|
),
|
|
),
|
|
body: _buildBody(context, controller),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildBody(BuildContext context, ChatSettingsController controller) {
|
|
try {
|
|
return Column(
|
|
children: [
|
|
// 用户信息区域
|
|
_buildUserInfoSection(controller),
|
|
|
|
// 分隔线
|
|
Container(
|
|
height: 8.h,
|
|
color: Color(0xFFF5F5F5),
|
|
),
|
|
|
|
// 设置选项
|
|
_buildSettingsList(controller),
|
|
|
|
// 间隔
|
|
SizedBox(height: 17.h),
|
|
|
|
// 关注按钮
|
|
_buildFollowButton(controller),
|
|
|
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 20.h),
|
|
],
|
|
);
|
|
} catch (e, stackTrace) {
|
|
print('❌ [ChatSettingsPage] _buildBody 失败: $e');
|
|
print('堆栈跟踪: $stackTrace');
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text('页面加载失败: $e'),
|
|
SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: () => Get.back(),
|
|
child: Text('返回'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// 用户信息区域
|
|
Widget _buildUserInfoSection(ChatSettingsController controller) {
|
|
try {
|
|
final avatarUrl = controller.getAvatarUrl();
|
|
final displayName = controller.getDisplayName();
|
|
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
|
|
child: Row(
|
|
children: [
|
|
// 头像
|
|
ClipOval(
|
|
child: avatarUrl != null && avatarUrl.isNotEmpty
|
|
? Image.network(
|
|
avatarUrl,
|
|
width: 50.w,
|
|
height: 50.w,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Image.asset(
|
|
Assets.imagesAvatarsExample,
|
|
width: 50.w,
|
|
height: 50.w,
|
|
fit: BoxFit.cover,
|
|
);
|
|
},
|
|
)
|
|
: Image.asset(
|
|
Assets.imagesAvatarsExample,
|
|
width: 50.w,
|
|
height: 50.w,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
|
|
SizedBox(width: 12.w),
|
|
|
|
// 昵称(优先显示备注名)
|
|
Expanded(
|
|
child: Text(
|
|
displayName,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
),
|
|
|
|
// 右箭头
|
|
Icon(
|
|
Icons.arrow_forward_ios,
|
|
size: 16.w,
|
|
color: Color(0xFF999999),
|
|
),
|
|
],
|
|
),
|
|
).onTap(() {
|
|
// 点击跳转到用户详情页
|
|
try {
|
|
controller.navigateToUserProfile();
|
|
} catch (e) {
|
|
print('❌ [ChatSettingsPage] 跳转失败: $e');
|
|
}
|
|
});
|
|
} catch (e, stackTrace) {
|
|
print('❌ [ChatSettingsPage] _buildUserInfoSection 失败: $e');
|
|
print('堆栈跟踪: $stackTrace');
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
|
|
child: Row(
|
|
children: [
|
|
ClipOval(
|
|
child: Image.asset(
|
|
Assets.imagesAvatarsExample,
|
|
width: 50.w,
|
|
height: 50.w,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Text(
|
|
controller.userId.isNotEmpty ? controller.userId : '加载中...',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.arrow_forward_ios,
|
|
size: 16.w,
|
|
color: Color(0xFF999999),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// 设置选项列表
|
|
Widget _buildSettingsList(ChatSettingsController controller) {
|
|
return Column(
|
|
children: [
|
|
// 设置备注名
|
|
_buildSettingItem(
|
|
title: '设置备注名',
|
|
showArrow: true,
|
|
onTap: () {
|
|
// TODO: 打开设置备注名弹窗
|
|
_showSetRemarkDialog(controller);
|
|
},
|
|
),
|
|
|
|
_buildDivider(),
|
|
|
|
// 加入黑名单
|
|
_buildSwitchItem(
|
|
title: '加入黑名单',
|
|
value: controller.isBlacklisted.value,
|
|
onChanged: (value) {
|
|
controller.toggleBlacklist(value);
|
|
},
|
|
controller: controller,
|
|
),
|
|
|
|
_buildDivider(),
|
|
|
|
// 举报
|
|
_buildSettingItem(
|
|
title: '举报',
|
|
showArrow: true,
|
|
onTap: () {
|
|
// TODO: 跳转到举报页面
|
|
controller.reportUser();
|
|
},
|
|
),
|
|
|
|
_buildDivider(),
|
|
|
|
],
|
|
);
|
|
}
|
|
|
|
// 设置项(带箭头)
|
|
Widget _buildSettingItem({
|
|
required String title,
|
|
bool showArrow = false,
|
|
VoidCallback? onTap,
|
|
}) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
),
|
|
if (showArrow)
|
|
Icon(
|
|
Icons.arrow_forward_ios,
|
|
size: 16.w,
|
|
color: Color(0xFF999999),
|
|
),
|
|
],
|
|
),
|
|
).onTap(onTap);
|
|
}
|
|
|
|
// 开关项
|
|
Widget _buildSwitchItem({
|
|
required String title,
|
|
required bool value,
|
|
required ValueChanged<bool> onChanged,
|
|
required ChatSettingsController controller,
|
|
}) {
|
|
return GetBuilder<ChatSettingsController>(
|
|
builder: (ctrl) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
),
|
|
CupertinoSwitch(
|
|
value: ctrl.isBlacklisted.value,
|
|
onChanged: onChanged,
|
|
activeColor: Color.fromRGBO(117, 98, 249, 1),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
// 分隔线
|
|
Widget _buildDivider() {
|
|
return Container(
|
|
margin: EdgeInsets.only(left: 16.w),
|
|
height: 1.h,
|
|
color: Color(0xFFF5F5F5),
|
|
);
|
|
}
|
|
|
|
// 关注按钮
|
|
Widget _buildFollowButton(ChatSettingsController controller) {
|
|
return GetBuilder<ChatSettingsController>(
|
|
builder: (ctrl) {
|
|
try {
|
|
final isFollowing = ctrl.isFollowing.value;
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w),
|
|
width: double.infinity,
|
|
height: 50.h,
|
|
child: ElevatedButton(
|
|
onPressed: () {
|
|
try {
|
|
ctrl.toggleFollow();
|
|
} catch (e) {
|
|
print('❌ [ChatSettingsPage] 切换关注状态失败: $e');
|
|
}
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Color.fromRGBO(117, 98, 249, 1),
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24.r),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
child: Text(
|
|
isFollowing ? '已关注' : '关注',
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
} catch (e) {
|
|
print('❌ [ChatSettingsPage] _buildFollowButton 失败: $e');
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w),
|
|
width: double.infinity,
|
|
height: 50.h,
|
|
child: ElevatedButton(
|
|
onPressed: () {},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Color.fromRGBO(117, 98, 249, 1),
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24.r),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
child: Text(
|
|
'关注',
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
// 设置备注名对话框
|
|
void _showSetRemarkDialog(ChatSettingsController controller) {
|
|
final TextEditingController textController = TextEditingController(
|
|
text: controller.remark.value, // 预填充当前备注名
|
|
);
|
|
|
|
Get.dialog(
|
|
AlertDialog(
|
|
title: Text('设置备注名'),
|
|
content: TextField(
|
|
controller: textController,
|
|
decoration: InputDecoration(
|
|
hintText: '请输入备注名',
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
),
|
|
autofocus: true,
|
|
maxLength: 20, // 限制最大长度
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Get.back(),
|
|
child: Text(
|
|
'取消',
|
|
style: TextStyle(color: Color(0xFF999999)),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
final remark = textController.text.trim();
|
|
if (remark.isNotEmpty) {
|
|
controller.setRemark(remark);
|
|
Get.back();
|
|
} else {
|
|
// 如果输入为空,清除备注名
|
|
controller.setRemark('');
|
|
Get.back();
|
|
}
|
|
},
|
|
child: Text(
|
|
'确定',
|
|
style: TextStyle(color: Color(0xFFA05CFF)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|