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.
454 lines
17 KiB
454 lines
17 KiB
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:dating_touchme_app/components/page_appbar.dart';
|
|
import 'package:dating_touchme_app/controller/mine/my_friend_controller.dart';
|
|
import 'package:dating_touchme_app/extension/ex_widget.dart';
|
|
import 'package:dating_touchme_app/generated/assets.dart';
|
|
import 'package:dating_touchme_app/model/mine/friend_data.dart';
|
|
import 'package:easy_refresh/easy_refresh.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
import '../../model/mine/friend_apply_data.dart' as fa;
|
|
|
|
class MyFriendPage extends StatelessWidget {
|
|
const MyFriendPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetX<MyFriendController>(
|
|
init: MyFriendController(),
|
|
builder: (controller){
|
|
return Scaffold(
|
|
appBar: PageAppbar(title: "我的好友"),
|
|
body: 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('推荐列表下拉刷新被触发');
|
|
if(controller.tab.value == 0){
|
|
controller.page.value = 1;
|
|
controller.friendList.clear();
|
|
await controller.getFriendList();
|
|
controller.listRefreshController.finishRefresh(IndicatorResult.success);
|
|
controller.listRefreshController.finishLoad(IndicatorResult.none);
|
|
} else {
|
|
controller.applyPage.value = 1;
|
|
controller.friendApplyList.clear();
|
|
await controller.getFriendApplyList();
|
|
controller.listRefreshController.finishRefresh(IndicatorResult.success);
|
|
controller.listRefreshController.finishLoad(IndicatorResult.none);
|
|
}
|
|
},
|
|
// 上拉加载更多
|
|
onLoad: () async {
|
|
print('推荐列表上拉加载被触发, hasMore: ');
|
|
if(controller.tab.value == 0){
|
|
controller.page.value += 1;
|
|
controller.getFriendList();
|
|
} else {
|
|
controller.applyPage.value += 1;
|
|
controller.getFriendApplyList();
|
|
}
|
|
},
|
|
child: SingleChildScrollView(
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 12.w),
|
|
constraints: BoxConstraints(
|
|
minHeight: MediaQuery.of(context).size.height - MediaQuery.of(context).padding.top,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
TDTabBar(
|
|
tabs: [
|
|
TDTab(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(right: 16, left: 16),
|
|
child: Text('我的好友'),
|
|
),
|
|
),
|
|
TDTab(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(right: 16, left: 16),
|
|
child: Text('好友申请'),
|
|
),
|
|
),
|
|
],
|
|
backgroundColor: Colors.transparent,
|
|
labelPadding: const EdgeInsets.only(right: 4, top: 10, bottom: 10, left: 4),
|
|
selectedBgColor: const Color.fromRGBO(108, 105, 244, 1),
|
|
unSelectedBgColor: Colors.transparent,
|
|
labelColor: Colors.white,
|
|
dividerHeight: 0,
|
|
tabAlignment: TabAlignment.start,
|
|
outlineType: TDTabBarOutlineType.capsule,
|
|
controller: controller.tabController,
|
|
showIndicator: false,
|
|
isScrollable: true,
|
|
onTap: (index) async {
|
|
print('相亲页面 Tab: $index');
|
|
controller.tab.value = index;
|
|
if(index == 0){
|
|
controller.friendList.clear();
|
|
controller.page.value = 1;
|
|
await controller.getFriendList();
|
|
controller.listRefreshController.finishRefresh(IndicatorResult.success);
|
|
controller.listRefreshController.finishLoad(IndicatorResult.none);
|
|
} else {
|
|
controller.friendApplyList.clear();
|
|
controller.applyPage.value = 1;
|
|
await controller.getFriendApplyList();
|
|
controller.listRefreshController.finishRefresh(IndicatorResult.success);
|
|
controller.listRefreshController.finishLoad(IndicatorResult.none);
|
|
}
|
|
},
|
|
),
|
|
if((controller.tab.value == 0 && controller.friendList.isEmpty) || (controller.tab.value == 1 && controller.friendApplyList.isEmpty)) ...[
|
|
Container(
|
|
padding: EdgeInsets.only(top: 60.w,bottom: 13.w),
|
|
child: Center(
|
|
child: Image.asset(
|
|
Assets.imagesEmptyIcon,
|
|
width: 91.w,
|
|
height: 91.w,
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
"你还没有关注任何人噢",
|
|
style: TextStyle(
|
|
fontSize: 12.w,
|
|
fontWeight: FontWeight.w500,
|
|
color: const Color.fromRGBO(144, 144, 144, 1)
|
|
),
|
|
),
|
|
Container(
|
|
width: 151.w,
|
|
height: 32.w,
|
|
margin: EdgeInsets.only(top: 11.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(32.w)),
|
|
gradient: LinearGradient(
|
|
begin: Alignment.centerLeft,
|
|
end: Alignment.centerRight,
|
|
stops: [0.0, 0.7753, 1.0],
|
|
colors: [
|
|
Color.fromRGBO(131, 89, 255, 1),
|
|
Color.fromRGBO(77, 127, 231, 1),
|
|
Color.fromRGBO(61, 138, 224, 1),
|
|
],
|
|
),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"去聊聊",
|
|
style: TextStyle(
|
|
fontSize: 12.w,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
if(controller.tab.value == 0 && controller.friendList.isNotEmpty) ...[
|
|
...controller.friendList.map((e){
|
|
return UserItem(item: e,);
|
|
}),
|
|
],
|
|
if(controller.tab.value == 1 && controller.friendApplyList.isNotEmpty) ...[
|
|
...controller.friendApplyList.map((e){
|
|
return AddUserItem(item: e, controller: controller,);
|
|
}),
|
|
]
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class UserItem extends StatefulWidget {
|
|
final Records item;
|
|
const UserItem({super.key, required this.item});
|
|
|
|
@override
|
|
State<UserItem> createState() => _UserItemState();
|
|
}
|
|
|
|
class _UserItemState extends State<UserItem> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(
|
|
vertical: 15.w
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.all(Radius.circular(45.w)),
|
|
child: CachedNetworkImage(
|
|
imageUrl: "${widget.item.profilePhoto ?? ""}?x-oss-process=image/format,webp/resize,w_170",
|
|
width: 45.w,
|
|
height: 45.w,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
SizedBox(width: 9.w,),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
"${widget.item.nickName}",
|
|
style: TextStyle(
|
|
fontSize: 14.w,
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 7.w),
|
|
width: 12.w,
|
|
height: 12.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(12.w)),
|
|
color: widget.item.genderCode == 0 ? const Color.fromRGBO(237, 245, 255, 1) : const Color.fromRGBO(255, 237, 255, 1)
|
|
),
|
|
child: Center(
|
|
child: Image.asset(
|
|
widget.item.genderCode == 0 ? Assets.imagesMale : Assets.imagesFemale,
|
|
width: 7.w,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
Text(
|
|
"${widget.item.age}岁·${widget.item.cityName}",
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
color: const Color.fromRGBO(144, 144, 144, 1),
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
Container(
|
|
width: 60.w,
|
|
height: 22.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(22.w)),
|
|
color: const Color.fromRGBO(224, 224, 224, .5)
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"已关注",
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
color: const Color.fromRGBO(144, 144, 144, 1),
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class AddUserItem extends StatefulWidget {
|
|
final fa.Records item;
|
|
final MyFriendController controller;
|
|
const AddUserItem({super.key, required this.item, required this.controller});
|
|
|
|
@override
|
|
State<AddUserItem> createState() => _AddUserItemState();
|
|
}
|
|
|
|
class _AddUserItemState extends State<AddUserItem> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(
|
|
vertical: 15.w
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.all(Radius.circular(45.w)),
|
|
child: CachedNetworkImage(
|
|
imageUrl: "${widget.item.toProfilePhoto ?? ""}?x-oss-process=image/format,webp/resize,w_170",
|
|
width: 45.w,
|
|
height: 45.w,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
SizedBox(width: 9.w,),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
"${widget.item.toNickName}",
|
|
style: TextStyle(
|
|
fontSize: 14.w,
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 7.w),
|
|
width: 12.w,
|
|
height: 12.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(12.w)),
|
|
color: widget.item.toGenderCode == 0 ? const Color.fromRGBO(237, 245, 255, 1) : const Color.fromRGBO(255, 237, 255, 1)
|
|
),
|
|
child: Center(
|
|
child: Image.asset(
|
|
widget.item.toGenderCode == 0 ? Assets.imagesMale : Assets.imagesFemale,
|
|
width: 7.w,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
Text(
|
|
"${widget.item.age}岁·${widget.item.cityName}",
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
color: const Color.fromRGBO(144, 144, 144, 1),
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
if(widget.item.status == 2) Container(
|
|
width: 60.w,
|
|
height: 22.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(22.w)),
|
|
color: const Color.fromRGBO(224, 224, 224, .5)
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"已同意",
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
color: const Color.fromRGBO(144, 144, 144, 1),
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if(widget.item.status == 3) Container(
|
|
width: 60.w,
|
|
height: 22.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(22.w)),
|
|
color: const Color.fromRGBO(224, 224, 224, .5)
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"已拒绝",
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
color: const Color.fromRGBO(144, 144, 144, 1),
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if(widget.item.status == 1) Container(
|
|
width: 60.w,
|
|
height: 22.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(22.w)),
|
|
border: Border.all(width: 1, color: const Color.fromRGBO(144, 144, 144, 1)),
|
|
color: Colors.white
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"同意",
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
),
|
|
),
|
|
).onTap((){
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
// 返回一个 AlertDialog 组件
|
|
return AlertDialog(
|
|
title: Text("提示"),
|
|
content: Text("请确认是否同意添加对方为好友"),
|
|
actions: <Widget>[
|
|
// 通常是按钮
|
|
TextButton(
|
|
child: Text("同意"),
|
|
onPressed: () async {
|
|
await widget.controller.applyFriend(widget.item.id ?? "", 2, widget.item);
|
|
Navigator.of(context).pop();
|
|
setState(() {
|
|
|
|
});
|
|
},
|
|
),
|
|
// 通常是按钮
|
|
TextButton(
|
|
child: Text("拒绝"),
|
|
onPressed: () async {
|
|
await widget.controller.applyFriend(widget.item.id ?? "", 3, widget.item);
|
|
Navigator.of(context).pop();
|
|
setState(() {
|
|
|
|
});
|
|
},
|
|
),
|
|
],
|
|
);
|
|
});
|
|
})
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|