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.
 
 
 
 
 

729 lines
29 KiB

import 'package:cached_network_image/cached_network_image.dart';
import 'package:dating_touchme_app/controller/global.dart';
import 'package:dating_touchme_app/controller/mine/mine_controller.dart';
import 'package:dating_touchme_app/extension/ex_widget.dart';
import 'package:dating_touchme_app/model/mine/user_count_data.dart';
import 'package:dating_touchme_app/network/user_api.dart';
import 'package:dating_touchme_app/pages/home/timeline_item.dart';
import 'package:dating_touchme_app/pages/home/user_information_page.dart';
import 'package:dating_touchme_app/pages/mine/edit_info_page.dart';
import 'package:dating_touchme_app/pages/mine/my_friend_page.dart';
import 'package:dating_touchme_app/pages/mine/vip_page.dart';
import 'package:dating_touchme_app/pages/setting/setting_page.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:dating_touchme_app/generated/assets.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../discover/visitor_list_page.dart';
import 'open_webview.dart';
class MinePage extends StatefulWidget {
const MinePage({super.key});
@override
State<MinePage> createState() => _MinePageState();
}
class _MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin{
late MineController controller;
final countData = UserCountData(friendNum: 0, friendApplyNum: 0, visitorNum:0).obs;
late UserApi _userApi;
final infoList = <Map>[
{"label": "好友", "num": 0, "type": 1},
{"label": "好友申请", "num": 0, "type": 2},
{"label": "访客", "num": 0, "type": 3},
].obs;
@override
void initState() {
super.initState();
// 确保 HomeController 已注册
if (!Get.isRegistered<MineController>()) {
controller = Get.put(MineController());
} else {
controller = Get.find<MineController>();
}
_userApi = Get.find<UserApi>();
getUserCount();
}
getUserCount() async {
try {
final response = await _userApi.userGetDongwoOwnUserCount();
if (response.data.isSuccess && response.data.data != null) {
countData.value = response.data.data ?? UserCountData(friendNum: 0, friendApplyNum: 0, visitorNum:0);
infoList.value = [
{"label": "好友", "num": countData.value.friendNum, "type": 1},
{"label": "好友申请", "num": countData.value.friendApplyNum, "type": 2},
{"label": "访客", "num": countData.value.visitorNum, "type": 3},
];
setState(() {
});
} else {
// 响应失败,抛出异常
throw Exception(response.data.message ?? '获取数据失败');
}
} catch(e){
print('用户数据获取失败: $e');
SmartDialog.showToast('用户数据获取失败');
rethrow;
}
}
@override
Widget build(BuildContext context) {
super.build(context);
return GetX<MineController>(
init: MineController(),
builder: (controller) {
controller.userData.value = GlobalData().userData;
controller.userId.value = GlobalData().userId;
return Container(
color: Colors.white,
child: EasyRefresh(
controller: controller.listRefreshController,
header: const ClassicHeader(
dragText: '下拉刷新',
armedText: '释放刷新',
readyText: '刷新中...',
processingText: '刷新中...',
processedText: '刷新完成',
failedText: '刷新失败',
noMoreText: '没有更多数据',
showMessage: false
),
footer: ClassicFooter(
dragText: '上拉加载',
armedText: '释放加载',
readyText: '加载中...',
processingText: '加载中...',
processedText: '加载完成',
failedText: '加载失败',
noMoreText: '没有更多数据',
showMessage: false
),
// 下拉刷新
onRefresh: () async {
print('推荐列表下拉刷新被触发');
controller.page.value = 1;
controller.postList.clear();
await controller.getPostList();
controller.listRefreshController.finishRefresh(IndicatorResult.success);
controller.listRefreshController.finishLoad(IndicatorResult.none);
},
// 上拉加载更多
onLoad: () async {
print('推荐列表上拉加载被触发, hasMore: ');
controller.page.value += 1;
await controller.getPostList();
},
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 9.w),
constraints: BoxConstraints(minHeight: ScreenUtil().setHeight(800)),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(248, 242, 255, 1.0), // rgba(248, 242, 255, 1)
Color.fromRGBO(247, 247, 247, 1.0), // rgba(247, 247, 247, 1)
],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
Container(
height: 75.w,
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top,
left: 10.w,
right: 10.w
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.settings,
size: 20.w,
).onTap(() {
Get.to(() => SettingPage());
})
],
),
),
Container(
width: 356.w,
padding: EdgeInsets.only(
left: 6.w,
right: 5.w
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(60.w)),
child: (controller.userData.value?.profilePhoto?.isNotEmpty ?? false) ? CachedNetworkImage(
imageUrl: "${controller.userData.value?.profilePhoto ?? ""}?x-oss-process=image/format,webp/resize,w_120",
width: 60.w,
height: 60.w,
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
) : Image.asset(
Assets.imagesUserAvatar,
width: 60.w,
height: 60.w,
)
),
SizedBox(width: 14.w,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 120.w, // 最大宽度
),
child: Text(
"${controller.userData.value?.nickName ?? ""}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 18.w,
color: const Color.fromRGBO(51, 51, 51, 1),
fontWeight: FontWeight.w700
),
),
),
SizedBox(width: 8.w,),
// Image.asset(
// Assets.imagesVip,
// width: 44.w,
// height: 16.w,
// )
if(false) Container(
width: 32.w,
height: 16.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
color: const Color.fromRGBO(201, 201, 201, 1)
),
child: Center(
child: Image.asset(
Assets.imagesVipFont,
width: 20.w,
height: 8.w,
),
),
)
],
),
Text(
"ID:${controller.userId.value ?? ""}",
style: TextStyle(
fontSize: 12.w,
color: const Color.fromRGBO(51, 51, 51, 1),
fontWeight: FontWeight.w500
),
)
],
)
],
),
InkWell(
onTap: (){
// Get.to(() => UserInformationPage(miId: controller.userData.value?.id ?? "", userId: GlobalData().userId ?? ""));
Get.to(() => EditInfoPage());
},
child: Row(
children: [
Image.asset(
Assets.imagesEdit,
width: 10.w,
height: 10.w,
),
SizedBox(width: 4.w,),
Text(
"编辑资料",
style: TextStyle(
fontSize: 12.w,
color: const Color.fromRGBO(55, 57, 72, 1),
fontWeight: FontWeight.w500
),
),
],
),
)
],
),
),
SizedBox(height: 16.w,),
if(false)Container(
height: 57.w,
padding: EdgeInsets.only(
top: 11.w,
right: 42.w,
bottom: 8.w,
left: 42.w
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(9.w)),
color: Colors.white,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
...infoList.map((e){
return InfoItem(item: e, getUserCount: getUserCount,);
}),
],
),
),
SizedBox(height: 10.w,),
Obx(
() {
return Column(
children: [
TDTabBar(
tabs: [
TDTab(text: '我的动态'),
TDTab(text: '人格类型'),
],
backgroundColor: Colors.transparent,
physics: const NeverScrollableScrollPhysics(),
controller: controller.tabController,
showIndicator: true,
isScrollable: true,
onTap: (int i) async {
controller.changeTab(i);
},
),
SizedBox(height: 10.w,),
if(controller.tab.value == 0) ...[
...controller.postList.map((e){
return TimelineItem(item: e);
}),
if(controller.postList.isEmpty) Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
Assets.imagesNoMoreTimeline,
width: 90.w,
height: 112.w,
),
SizedBox(height: 5.w,),
Text(
"暂无动态",
style: TextStyle(
fontSize: 14.w,
color: const Color.fromRGBO(186, 186, 186, 1)
),
)
],
),
)
],
if(controller.tab.value == 1) ...[
Stack(
clipBehavior: Clip.none,
children: [
Container(),
Positioned(
left: -9.w,
child: Image.asset(
Assets.imagesResultsBg,
width: 375.w,
),
),
Positioned(
left: 7.w,
top: 32.w,
child: SizedBox(
width: 95.w,
child: Text(
"你的人格类型鉴定结果",
style: TextStyle(
fontSize: 16.w,
color: Colors.white
),
),
),
),
Positioned(
right: 2.w,
top: 35.w,
child: Text(
"${controller.resultTitle.value != "" ? controller.resultTitle.value : "????"}",
style: TextStyle(
fontSize: 24.w,
color: const Color.fromRGBO(117, 98, 249, 1),
fontWeight: FontWeight.w700
),
),
),
Positioned(
left: -2.w,
top: 134.w,
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
Assets.imagesElementBorder,
width: 91.w,
height: 52.w,
),
Text(
"${controller.resultTitle.value != "" ? controller.resultData.value["优势"][0] : "???"}",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
)
],
),
),
Positioned(
left: 2.w,
top: 259.w,
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
Assets.imagesElementBorder,
width: 91.w,
height: 52.w,
),
Text(
"${controller.resultTitle.value != "" ? controller.resultData.value["优势"][1] : "???"}",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
)
],
),
),
Positioned(
right: 1.w,
top: 134.w,
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
Assets.imagesElementBorder,
width: 91.w,
height: 52.w,
),
Text(
"${controller.resultTitle.value != "" ? controller.resultData.value["优势"][2] : "???"}",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
)
],
),
),
Positioned(
right: 1.w,
top: 251.w,
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
Assets.imagesElementBorder,
width: 91.w,
height: 52.w,
),
Text(
"${controller.resultTitle.value != "" ? controller.resultData.value["优势"][3] : "???"}",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
)
],
),
),
],
)
],
],
);
}
),
],
),
),
),
),
);
},
);
}
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}
class InfoItem extends StatefulWidget {
final Map item;
final Function getUserCount;
const InfoItem({super.key, required this.item, required this.getUserCount});
@override
State<InfoItem> createState() => _InfoItemState();
}
class _InfoItemState extends State<InfoItem> {
@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
alignment: widget.item["type"] == 1 ? Alignment.centerLeft : widget.item["type"] == 2 ? Alignment.center : Alignment.centerRight,
child: Column(
children: [
Stack(
clipBehavior: Clip.none,
children: [
Text(
"${widget.item["num"]}",
style: TextStyle(
fontSize: 15.w,
color: Colors.black,
fontWeight: FontWeight.w700
),
),
if(widget.item["type"] == 2 && widget.item["num"] != 0)Positioned(
right: -5.w,
top: 0,
child: Container(
width: 5.w,
height: 5.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.w)),
color: const Color.fromRGBO(255, 87, 51, 1)
),
),
)
],
),
Text(
widget.item["label"],
style: TextStyle(
fontSize: 10.w,
color: const Color.fromRGBO(166, 166, 166, 1),
),
)
],
)
).onTap((){
if(widget.item['type'] == 3){
Get.to(()=> VisitorListPage())?.then((w) async {
await widget.getUserCount();
setState(() {
});
});
} else {
Get.to(()=> MyFriendPage())?.then((w) async {
await widget.getUserCount();
setState(() {
});
});
}
})
);
}
}
class BlockItem extends StatefulWidget {
final Map item;
final bool showWaring;
final Function path;
const BlockItem({super.key, required this.item, this.showWaring = false, required this.path});
@override
State<BlockItem> createState() => _BlockItemState();
}
class _BlockItemState extends State<BlockItem> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: (){
// context.pushNamed(widget.path);
if(widget.path() != null){
Get.to(widget.path)?.then((e){
setState(() {
});
});
} else {
SmartDialog.showToast('功能暂未开放');
}
// RouteGuardService.to.toWithAuth(widget.path, null);
},
child: Container(
height: 48.w,
padding: EdgeInsets.only(left: 16.w),
decoration: BoxDecoration(
color: Colors.white
),
child: Container(
padding: EdgeInsets.only(right: 16.w),
decoration: BoxDecoration(
border: widget.item["title"] != "红娘等级" ? Border(
bottom: BorderSide(width: 1, color: const Color.fromRGBO(238, 238, 238, 1))
) : null
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Image.asset(
widget.item["icon"],
height: 22.w,
width: 22.w,
),
SizedBox(width: 16.w,),
Text(
widget.item["title"],
style: TextStyle(
fontSize: 14.w,
color: Colors.black,
fontWeight: FontWeight.w500
),
)
],
),
Row(
children: [
if(widget.showWaring) Container(
width: 5.w,
height: 5.w,
margin: EdgeInsets.only(right: 4.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.w)),
color: const Color.fromRGBO(255, 87, 51, 1)
),
),
if(widget.item["title"] == "认证中心") Text(
widget.item["subTitle"],
style: TextStyle(
fontSize: 11.w,
color: const Color.fromRGBO(166, 166, 166, 1)
),
),
SizedBox(width: 10.w,),
Image.asset(
Assets.imagesArrow,
width: 4.w,
)
],
)
],
),
),
),
);
}
}
class SettingItem extends StatefulWidget {
final Map item;
final Function path;
const SettingItem({super.key, required this.item, required this.path});
@override
State<SettingItem> createState() => _SettingItemState();
}
class _SettingItemState extends State<SettingItem> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: (){
if(widget.path() == null){
SmartDialog.showToast('功能暂未开放');
return;
}
// context.pushNamed(widget.path);
Get.to(widget.path);
// RouteGuardService.to.toWithAuth(widget.path, null);
},
child: Container(
height: 48.w,
padding: EdgeInsets.symmetric(horizontal: 16.w),
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Image.asset(
widget.item["icon"],
width: 24.w,
height: 24.w,
),
SizedBox(width: 14.w,),
Text(
widget.item["title"],
style: TextStyle(
fontSize: 14.w,
fontWeight: FontWeight.w500,
color: Colors.black
),
)
],
),
Image.asset(
Assets.imagesArrow,
width: 4.w,
height: 8.w,
)
],
),
),
);
}
}