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

498 lines
19 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:provider/provider.dart';
import 'package:readmore/readmore.dart';
import 'package:aslan/app_localizations.dart';
import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart';
import 'package:aslan/chatvibe_ui/components/dialog/dialog_base.dart';
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
import 'package:aslan/chatvibe_ui/components/at_page_list.dart';
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
import 'package:aslan/chatvibe_ui/theme/chatvibe_theme.dart';
import 'package:aslan/chatvibe_core/at_lk_event_bus.dart';
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
import 'package:aslan/chatvibe_core/utilities/at_dialog_utils.dart';
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
import 'package:aslan/chatvibe_data/sources/repositories/dynamic_repository_imp.dart';
import 'package:aslan/chatvibe_domain/models/res/dynamic_list_res.dart';
import 'package:aslan/chatvibe_managers/user_profile_manager.dart';
import 'package:aslan/chatvibe_features/index/main_route.dart';
import 'package:aslan/chatvibe_features/dynamic/dynamic_route.dart';
class DynamicFollowingPage extends ATPageList {
@override
_DynamicFollowingPageState createState() => _DynamicFollowingPageState();
}
class _DynamicFollowingPageState
extends ATPageListState<Records, DynamicFollowingPage> {
late StreamSubscription _subscription;
@override
void initState() {
super.initState();
enablePullUp = true;
backgroundColor = Colors.transparent;
isShowDivider = true;
isShowFooter = false;
padding = EdgeInsets.only(bottom: 5.w);
loadData(1);
_subscription = eventBus.on<UpdateDynamicEvent>().listen((event) {
if (mounted) {
loadData(1);
}
});
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: buildList(context),
);
}
@override
Widget buildItem(Records res) {
return ATDebounceWidget(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SizedBox(width: 10.w),
ATDebounceWidget(
child: netImage(
url: res.userProfile?.userAvatar ?? "",
shape: BoxShape.circle,
height: 45.w,
width: 45.w,
),
onTap: () {
ATNavigatorUtils.push(
context,
"${MainRoute.person}?isMe=${AccountStorage().getCurrentUser()?.userProfile?.id == res.userProfile?.id}&tageId=${res.userProfile?.id}",
);
},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
spacing: 3.w,
children: [
Container(
margin: EdgeInsetsDirectional.only(start: 5.w),
height: 21.w,
constraints: BoxConstraints(maxWidth: 95.w),
child: chatvibeNickNameText(
maxWidth: 95.w,
res.userProfile?.userNickname ?? "",
fontSize: 15.sp,
textColor: Colors.black,
fontWeight: FontWeight.w400,
type: res.userProfile?.getVIP()?.name ?? "",
needScroll:
(res
.userProfile
?.userNickname
?.characters
.length ??
0) >
10,
),
),
Container(
width:
(res.userProfile?.age ?? 0) > 999 ? 58.w : 48.w,
height: 24.w,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
res.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(res.userProfile?.userSex),
text(
"${res.userProfile?.age}",
textColor: Colors.white,
fontSize: 14.sp,
fontWeight: FontWeight.w600,
),
SizedBox(width: 3.w),
],
),
),
getVIPBadge(
res.userProfile?.getVIP()?.name,
width: 45.w,
height: 25.w,
),
],
),
Container(
alignment: AlignmentDirectional.centerStart,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(width: 5.w),
res.userProfile?.wearBadge?.isNotEmpty ?? false
? SizedBox(
height: 28.w,
child: ListView.separated(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount:
res.userProfile?.wearBadge?.length ?? 0,
itemBuilder: (context, index) {
return netImage(
width: 28.w,
height: 28.w,
url:
res
.userProfile
?.wearBadge?[index]
.selectUrl ??
"",
);
},
separatorBuilder: (
BuildContext context,
int index,
) {
return SizedBox(width: 5.w);
},
),
)
: Container(),
SizedBox(width: 5.w),
],
),
),
),
],
),
),
SizedBox(width: 5.w),
ATDebounceWidget(
child: Container(
padding: EdgeInsetsDirectional.all(3.w),
child: Icon(
Icons.more_vert,
color: Colors.black45,
size: 18.w,
),
),
onTap: () {
ATDialogUtils.revealDynamicCommentOptDialog(
context,
reportCallback:
res.userId !=
AccountStorage().getCurrentUser()?.userProfile?.id
? () {
ATNavigatorUtils.push(
context,
"${MainRoute.report}?type=dynamic&tageId=${res.dynamicId}",
replace: false,
);
}
: null,
deleteCallback:
res.userId ==
AccountStorage()
.getCurrentUser()
?.userProfile
?.id ||
(Provider.of<ChatVibeUserProfileManager>(
context,
listen: false,
).userIdentity?.admin ??
false)
? () {
SmartDialog.show(
tag: "showConfirmDialog",
alignment: Alignment.center,
debounce: true,
animationType: SmartAnimationType.fade,
builder: (_) {
return MsgDialog(
title: ATAppLocalizations.of(context)!.tips,
msg:
ATAppLocalizations.of(
context,
)!.deleteDynamicTips,
leftConfirm: true,
isBtnBgFlip: true,
btnText:
ATAppLocalizations.of(context)!.confirm,
onEnsure: () {
_deleteDynamic(res.dynamicId ?? "");
},
);
},
);
}
: null,
);
},
),
SizedBox(width: 3.w),
],
),
SizedBox(height: 3.w),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: Container(
margin: EdgeInsetsDirectional.symmetric(horizontal: 10.w),
child: ReadMoreText(
res.content ?? "",
trimLines: 3,
// 收缩时显示的行数
trimMode: TrimMode.Line,
style: TextStyle(
fontFamily: "MyCustomFont",
fontSize: 14.sp,
color: Colors.black,
fontWeight: FontWeight.w600,
),
// 按行截断
trimCollapsedText: ATAppLocalizations.of(context)!.showMore,
// 收缩时按钮文字
trimExpandedText: ATAppLocalizations.of(context)!.showLess,
// 展开时按钮文字
moreStyle: TextStyle(
color: ChatVibeTheme.primaryLight,
fontFamily: "MyCustomFont",
fontWeight: FontWeight.w600,
),
lessStyle: TextStyle(
color: ChatVibeTheme.primaryLight,
fontFamily: "MyCustomFont",
fontWeight: FontWeight.w600,
),
),
),
),
],
),
SizedBox(height: 5.w),
(res.pictures?.isNotEmpty ?? false)
? res.pictures?.length == 1
? Container(
margin: EdgeInsets.symmetric(horizontal: 10.w),
constraints: BoxConstraints(
maxWidth: ScreenUtil().screenWidth / 2,
),
child: ATDebounceWidget(
child: netImage(
url: res.pictures?.first.resourceUrl ?? "",
borderRadius: BorderRadius.circular(8.w),
),
onTap: () {
ATNavigatorUtils.push(
context,
"${DynamicRoute.detailForPic}?id=${res.dynamicId}&canGoUserInfo=true",
replace: false,
);
},
),
)
: Container(
child: GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:
res.pictures?.length == 2 ? 2 : 3, // 每行2个
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
padding: EdgeInsets.all(10),
itemCount: res.pictures?.length,
itemBuilder: (context, index) {
return ATDebounceWidget(
child: netImage(
url: res.pictures?[index].resourceUrl ?? "",
borderRadius: BorderRadius.circular(8.w),
),
onTap: () {
ATNavigatorUtils.push(
context,
"${DynamicRoute.detailForPic}?id=${res.dynamicId}&canGoUserInfo=true",
replace: false,
);
},
);
},
),
)
: Container(),
SizedBox(height: 10.w),
Row(
children: [
Row(
children: [
SizedBox(width: 10.w),
Image.asset(
"atu_images/dynamic/at_icon_reply.png",
height: 22.w,
color: Colors.grey,
),
SizedBox(width: 3.w),
text(
res.commentStrQuantity != "0"
? "${ATAppLocalizations.of(context)!.comment}(${res.commentStrQuantity})"
: ATAppLocalizations.of(context)!.catchFirstComment,
textColor: Colors.grey,
fontSize: 13.sp,
),
],
),
SizedBox(width: 25.w),
ATDebounceWidget(
child: Row(
children: [
Image.asset(
(res.like ?? false)
? "atu_images/dynamic/at_icon_like_red.png"
: "atu_images/dynamic/at_icon_like.png",
height: 22.w,
color: (res.like ?? false) ? null : Colors.grey,
),
SizedBox(width: 3.w),
text(
res.likeStrQuantity != "0"
? "${ATAppLocalizations.of(context)!.like}(${res.likeStrQuantity ?? 0})"
: ATAppLocalizations.of(context)!.like,
textColor: Colors.grey,
fontSize: 13.sp,
),
],
),
onTap: () {
_like(res);
},
),
],
),
SizedBox(height: 8.w),
Row(
children: [
SizedBox(width: 10.w),
netImage(
url:
AccountStorage().getCurrentUser()?.userProfile?.userAvatar ??
"",
shape: BoxShape.circle,
height: 32.w,
width: 32.w,
),
SizedBox(width: 8.w),
Expanded(
child: Container(
padding: EdgeInsetsDirectional.only(start: 10.w),
alignment: AlignmentDirectional.centerStart,
height: 28.w,
decoration: BoxDecoration(
color: Color(0xffF4EAFF),
borderRadius: BorderRadius.circular(16.w),
),
child: text(
ATAppLocalizations.of(context)!.saySomething,
textColor: Colors.grey,
fontSize: 13.sp,
),
),
),
SizedBox(width: 10.w),
],
),
],
),
onTap: () {
ATNavigatorUtils.push(
context,
"${DynamicRoute.detail}?id=${res.dynamicId}&canGoUserInfo=true",
replace: false,
);
},
);
}
@override
builderDivider() {
return Divider(height: 22.w, color: Color(0xffF2F2F2));
}
///加载数据
@override
loadPage({
required int page,
required Function(List<Records>) onSuccess,
Function? onErr,
}) async {
try {
var result = await DynamicRepositoryImp().dynamicListFollow(
current: page,
);
onSuccess(result.records ?? []);
} catch (e) {
if (onErr != null) {
onErr();
}
}
}
void _like(Records res) {
DynamicRepositoryImp()
.dynamicLike(res.dynamicId ?? "", !(res.like ?? false))
.then((result) {
res.setLike(!(res.like ?? false));
if (res.like ?? false) {
res.setLikeStrQuantity(
"${int.parse(res.likeStrQuantity ?? "0") + 1}",
);
} else {
res.setLikeStrQuantity(
"${int.parse(res.likeStrQuantity ?? "0") - 1}",
);
}
setState(() {});
})
.catchError((_) {});
}
void _deleteDynamic(String dynamicId) {
DynamicRepositoryImp()
.dynamicDelete(dynamicId)
.then((result) {
setState(() {
items.removeWhere((element) => element.dynamicId == dynamicId);
});
})
.catchError((e) {});
}
}