2026-07-01 18:25:58 +08:00

738 lines
24 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:aslan/app_localizations.dart';
import 'package:aslan/chatvibe_features/user/settings/settings_route.dart';
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
import 'package:aslan/chatvibe_ui/components/appbar/chatvibe_appbar.dart';
import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart';
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
import 'package:provider/provider.dart';
import '../../chatvibe_core/routes/at_fluro_navigator.dart';
import '../../chatvibe_data/sources/repositories/user_repository_impl.dart';
import '../../chatvibe_domain/models/res/at_user_counter_res.dart';
import '../../chatvibe_managers/user_profile_manager.dart';
import '../index/main_route.dart';
import '../store/store_route.dart';
import '../wallet/wallet_route.dart';
/// 新的"我的"页面基于Figma设计
/// 包含个人资料、统计信息、钱包和功能卡片
class MePage2 extends StatefulWidget {
const MePage2({super.key});
@override
_MePage2State createState() => _MePage2State();
}
class _MePage2State extends State<MePage2> {
Map<String, ATUserCounterRes> counterMap = {};
@override
void initState() {
super.initState();
_loadUserData();
}
void _loadUserData() {
Provider.of<ChatVibeUserProfileManager>(
context,
listen: false,
).getMyUserInfo();
Provider.of<ChatVibeUserProfileManager>(
context,
listen: false,
).getUserIdentity();
userCounter("${AccountStorage().getCurrentUser()?.userProfile?.id}");
Provider.of<ChatVibeUserProfileManager>(context, listen: false).balance();
}
void userCounter(String userId) async {
counterMap.clear();
var userCounterList = await AccountRepository().userCounter(userId);
counterMap = Map.fromEntries(
userCounterList.map(
(counter) => MapEntry(counter.counterType ?? "", counter),
),
);
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: false,
appBar: ChatVibeStandardAppBar(
title: '',
actions: [],
showBackButton: false,
backgroundColor: Colors.transparent,
),
body: _buildContent(),
);
}
Widget _buildContent() {
return Consumer<ChatVibeUserProfileManager>(
builder: (context, ref, child) {
return SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 个人资料区域
_buildProfileSection(),
SizedBox(height: 20.w),
// 统计信息卡片
_buildStatisticsCard(),
SizedBox(height: 8.w),
_buildWalletSection(),
SizedBox(height: 8.w),
// 功能卡片1
_buildFunctionCard1(),
SizedBox(height: 8.w),
// 功能卡片2
_buildFunctionCard2(),
SizedBox(height: 8.w),
// 功能卡片3
_buildFunctionCard3(),
SizedBox(height: 40.w),
],
),
);
},
);
}
Widget _buildProfileSection() {
return ATDebounceWidget(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 15.w),
child: Row(
children: [
// 头像
head(
url:
AccountStorage().getCurrentUser()?.userProfile?.userAvatar ??
'',
width: 72.w,
height: 72.w,
shape: BoxShape.circle,
headdress:
AccountStorage()
.getCurrentUser()
?.userProfile
?.getHeaddress()
?.sourceUrl,
showDefault: true,
),
SizedBox(width: 8.w),
// 昵称和ID
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
spacing: 3.w,
children: [
chatvibeNickNameText(
maxWidth: 135.w,
UserManager()
.getCurrentUser()
?.userProfile
?.userNickname ??
"",
textColor: Color(0xFF333333),
fontSize: 16.sp,
fontWeight: FontWeight.w600,
type:
UserManager()
.getCurrentUser()
?.userProfile
?.getVIP()
?.name ??
"",
needScroll:
(UserManager()
.getCurrentUser()
?.userProfile
?.userNickname
?.characters
.length ??
0) >
13,
),
getVIPBadge(
UserManager()
.getCurrentUser()
?.userProfile
?.getVIP()
?.name,
width: 65.w,
height: 28.w,
),
Container(
width:
(AccountStorage()
.getCurrentUser()
?.userProfile
?.age ??
0) >
999
? 58.w
: 48.w,
height: 24.w,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
AccountStorage()
.getCurrentUser()
?.userProfile
?.userSex ==
0
? "atu_images/login/at_icon_sex_woman_bg.png"
: "atu_images/login/at_icon_sex_man_bg.png",
),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
xb(
AccountStorage()
.getCurrentUser()
?.userProfile
?.userSex,
),
text(
"${AccountStorage().getCurrentUser()?.userProfile?.age}",
textColor: Colors.white,
fontSize: 14.sp,
fontWeight: FontWeight.w600,
),
SizedBox(width: 3.w),
],
),
),
],
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
Row(
children: [
getIdIcon(
AccountStorage()
.getCurrentUser()
?.userProfile
?.wealthLevel ??
0,
width: 32.w,
height: 32.w,
textColor: Color(0xFF333333),
fontSize: 16.sp,
fontWeight: FontWeight.w600,
),
chatvibeNickNameText(
maxWidth: 135.w,
AccountStorage()
.getCurrentUser()
?.userProfile
?.getID() ??
"",
textColor: Color(0xFF333333),
fontSize: 16.sp,
fontWeight: FontWeight.w600,
type: AccountStorage().getVIP()?.name ?? "",
needScroll:
(UserManager()
.getCurrentUser()
?.userProfile
?.getID()
.characters
.length ??
0) >
13,
),
],
),
SizedBox(width: 5.w),
getWealthLevel(
AccountStorage()
.getCurrentUser()
?.userProfile
?.wealthLevel ??
0,
width: 58.w,
height: 30.w,
),
SizedBox(width: 5.w),
getUserLevel(
AccountStorage()
.getCurrentUser()
?.userProfile
?.charmLevel ??
0,
width: 58.w,
height: 30.w,
),
],
),
),
],
),
),
// 设置/编辑图标
Icon(
ATGlobalConfig.lang == "ar"
? Icons.keyboard_arrow_left
: Icons.keyboard_arrow_right,
size: 25.w,
color: Colors.white,
),
],
),
),
onTap: () {
ATNavigatorUtils.push(
context,
"${MainRoute.person}?isMe=true&tageId=${AccountStorage().getCurrentUser()?.userProfile?.id}",
replace: false,
);
},
);
}
Widget _buildStatisticsCard() {
return Consumer<ChatVibeUserProfileManager>(
builder: (context, ref, child) {
return Container(
height: 72.w,
alignment: AlignmentDirectional.center,
width: ScreenUtil().screenWidth,
margin: EdgeInsets.symmetric(horizontal: 18.w),
padding: EdgeInsets.symmetric(horizontal: 35.w),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
text(
"${counterMap["INTERVIEW"]?.quantity ?? 0}",
fontSize: 16.sp,
textColor: Color(0xff333333),
fontWeight: FontWeight.w600,
),
text(
ATAppLocalizations.of(context)!.vistors,
fontSize: 14.sp,
textColor: Color(0xffB1B1B1),
),
],
),
onTap: () {
ATNavigatorUtils.push(context, MainRoute.vistors);
},
),
_buildStatDivider(),
GestureDetector(
onTap: () {
ATNavigatorUtils.push(context, MainRoute.follow);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
text(
"${counterMap["SUBSCRIPTION"]?.quantity ?? 0}",
fontSize: 16.sp,
textColor: Color(0xff333333),
fontWeight: FontWeight.w600,
),
text(
ATAppLocalizations.of(context)!.follow,
fontSize: 14.sp,
textColor: Color(0xffB1B1B1),
),
],
),
),
_buildStatDivider(),
GestureDetector(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
text(
"${counterMap["FANS"]?.quantity ?? 0}",
fontSize: 16.sp,
textColor: Color(0xff333333),
fontWeight: FontWeight.w600,
),
text(
ATAppLocalizations.of(context)!.fans,
fontSize: 14.sp,
textColor: Color(0xffB1B1B1),
),
],
),
onTap: () {
ATNavigatorUtils.push(context, MainRoute.fans);
},
),
],
),
);
},
);
}
Widget _buildStatDivider() {
return Container(
width: 0.5.w,
height: 16.w,
color: Color(0xFFE6E6E6),
margin: EdgeInsets.symmetric(horizontal: 8.w),
);
}
Widget _buildWalletSection() {
return ATDebounceWidget(
child: Container(
padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 20.w),
margin: EdgeInsets.symmetric(horizontal: 15.w),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('atu_images/index/at_icon_wallet_bg.png'),
),
),
child: Row(
children: [
// 左侧装饰图像
Image.asset(
'atu_images/index/at_icon_wallet_icon.png',
width: 60.w,
height: 60.w,
),
SizedBox(width: 12.w),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text(
ATAppLocalizations.of(context)!.wallet,
fontSize: 24.sp,
textColor: Colors.white,
fontWeight: FontWeight.w900,
fontStyle: FontStyle.italic,
),
SizedBox(height: 4.w),
Row(
children: [
Image.asset(
'atu_images/general/at_icon_jb.png',
width: 22.w,
height: 22.w,
),
SizedBox(width: 3.w),
Consumer<ChatVibeUserProfileManager>(
builder: (context, ref, child) {
return text(
ref.myBalance > 1000
? "${(ref.myBalance / 1000).toStringAsFixed(2)}k"
: "${ref.myBalance}",
fontSize: 15.sp,
textColor: Colors.white,
fontWeight: FontWeight.bold,
);
},
),
],
),
],
),
),
],
),
),
onTap: () {
ATNavigatorUtils.push(context, WalletRoute.recharge);
},
);
}
Widget _buildFunctionCard1() {
return Container(
margin: EdgeInsets.symmetric(horizontal: 15.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.w),
),
child: Column(
spacing: 5.w,
mainAxisSize: MainAxisSize.min,
children: [
_buildItem(
"atu_images/index/at_icon_task.png",
ATAppLocalizations.of(context)!.task,
() {
ATNavigatorUtils.push(context, MainRoute.taskList, replace: false);
},
),
_buildItem(
"atu_images/index/at_icon_vip.png",
ATAppLocalizations.of(context)!.vip,
() {
ATNavigatorUtils.push(context, MainRoute.vipList, replace: false);
},
),
_buildItem(
"atu_images/index/at_icon_shop.png",
ATAppLocalizations.of(context)!.store,
() {
ATNavigatorUtils.push(context, StoreRoute.list, replace: false);
},
),
_buildItem(
"atu_images/index/at_icon_my_items.png",
ATAppLocalizations.of(context)!.myItems,
() {
ATNavigatorUtils.push(context, StoreRoute.bags, replace: false);
},
),
_buildItem(
"atu_images/index/at_icon_level.png",
ATAppLocalizations.of(context)!.level,
() {
ATNavigatorUtils.push(
context,
MainRoute.levelList,
replace: false,
);
},
),
_buildItem(
"atu_images/index/at_icon_medals.png",
ATAppLocalizations.of(context)!.badgeHonor,
needLine: false,
() {
ATNavigatorUtils.push(
context,
MainRoute.medalsHonorListPage,
replace: false,
);
},
),
],
),
);
}
Widget _buildFunctionCard3() {
return Container(
margin: EdgeInsets.symmetric(horizontal: 15.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.w),
),
child: Column(
spacing: 5.w,
mainAxisSize: MainAxisSize.min,
children: [
_buildItem(
"atu_images/index/at_icon_settings.png",
ATAppLocalizations.of(context)!.settings,
needLine: false,
() {
ATNavigatorUtils.push(
context,
SettingsRoute.settings,
replace: false,
);
},
),
],
),
);
}
Widget _buildFunctionCard2() {
// 一次性获取用户身份信息(避免多次监听)
final userProfile = context.watch<ChatVibeUserProfileManager>();
final items = <Widget>[];
// 1. 主播相关
if (userProfile.userIdentity?.anchor ?? false) {
if (userProfile.userIdentity?.agent ?? false) {
items.add(
_buildItem(
"atu_images/index/at_icon_agent_center.png",
ATAppLocalizations.of(context)!.agentCenter,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.agencyCenterUrl)}&showTitle=false",
),
),
);
} else {
items.add(
_buildItem(
"atu_images/index/at_icon_host_center.png",
ATAppLocalizations.of(context)!.hostCenter,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.hostCenterUrl)}&showTitle=false",
),
),
);
}
} else {
items.add(
_buildItem(
"atu_images/index/at_icon_become_host_center.png",
ATAppLocalizations.of(context)!.becomeHost,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.anchorAgentUrl)}&showTitle=false",
),
),
);
}
// 2. BD 相关(非管理员时)
if (!(userProfile.userIdentity?.admin ?? false)) {
if (userProfile.userIdentity?.bdLeader ?? false) {
items.add(
_buildItem(
"atu_images/index/at_icon_bd_leader.png",
ATAppLocalizations.of(context)!.bdLeader,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.bdLeaderUrl)}&showTitle=false",
),
),
);
} else if (userProfile.userIdentity?.bd ?? false) {
items.add(
_buildItem(
"atu_images/index/at_icon_bd_center.png",
ATAppLocalizations.of(context)!.bdCenter,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.bdCenterUrl)}&showTitle=false",
),
),
);
}
}
// 3. 货运代理
if (userProfile.userIdentity?.freightAgent ?? false) {
items.add(
_buildItem(
"atu_images/index/at_icon_recharge_agency.png",
ATAppLocalizations.of(context)!.rechargeAgency,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.coinSellerUrl)}&showTitle=false",
),
),
);
}
// 4. 管理员注意你的原逻辑中管理员和上面BD逻辑有重叠这里按原样单独处理
if (userProfile.userIdentity?.admin ?? false) {
items.add(
_buildItem(
"atu_images/index/at_icon_admin_center.png",
ATAppLocalizations.of(context)!.adminCenter,
() => ATNavigatorUtils.push(
context,
"${MainRoute.webViewPage}?url=${Uri.encodeComponent(ATGlobalConfig.adminUrl)}&showTitle=false",
),
),
);
}
// 没有任何项时,不显示整个卡片
if (items.isEmpty) return const SizedBox.shrink();
return Container(
margin: EdgeInsets.symmetric(horizontal: 15.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.w),
),
child: Column(
spacing: 5.w,
mainAxisSize: MainAxisSize.min,
children: items,
),
);
}
_buildItem(
String icon,
String title,
Function() onTap, {
bool needLine = true,
}) {
return GestureDetector(
child: Column(
children: [
Container(
alignment: AlignmentDirectional.centerStart,
height: 48.w,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
SizedBox(width: 10.w),
Image.asset(icon, width: 26.w, height: 26.w),
SizedBox(width: 10.w),
Expanded(
child: text(
title,
textColor: Color(0xff333333),
fontSize: 16.sp,
fontWeight: FontWeight.w600,
),
),
Icon(
ATGlobalConfig.lang == "ar"
? Icons.keyboard_arrow_left
: Icons.keyboard_arrow_right,
color: Color(0xff333333),
size: 15.w,
),
SizedBox(width: 12.w),
],
),
],
),
),
needLine
? Container(
margin: EdgeInsets.symmetric(horizontal: 10.w),
height: 0.5.w,
color: Color(0xffE6E6E6),
)
: Container(),
],
),
onTap: () {
onTap();
},
);
}
}