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:aslan/chatvibe_ui/components/at_debounce_widget.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_data/sources/repositories/user_repository_impl.dart'; import 'package:provider/provider.dart'; import 'package:readmore/readmore.dart'; import 'package:aslan/app_localizations.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/components/at_tts.dart'; import 'package:aslan/chatvibe_ui/theme/chatvibe_theme.dart'; import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.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'; import '../../../chatvibe_core/at_lk_event_bus.dart'; class DynamicTrendPage extends ATPageList { @override _DynamicTrendPageState createState() => _DynamicTrendPageState(); } class _DynamicTrendPageState extends ATPageListState { 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().listen((event) { if (mounted) { loadData(1); } }); } @override void dispose() { _subscription.cancel(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, body: Column( children: [ Container( height: kToolbarHeight + ScreenUtil().statusBarHeight, alignment: Alignment.centerLeft, child: Row( children: [ SizedBox(width: 15.w), ATDebounceWidget( child: Container( alignment: Alignment.center, width: 95.w, height: 35.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(25.w)), gradient: LinearGradient( colors: [Color(0xff2647FF), Color(0xff7081FF)], begin: Alignment.topLeft, end: Alignment.bottomRight, ), boxShadow: [ BoxShadow( color: Color(0xffA289EC), offset: Offset(0, 4), blurRadius: 4, ), ], ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Image.asset( "atu_images/dynamic/at_icon_reply.png", height: 20.w, ), SizedBox(width: 3.w), text( ATAppLocalizations.of(context)!.reply, fontSize: 14.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), ), onTap: () { ATNavigatorUtils.push( context, DynamicRoute.dynamicMessageReply, replace: false, ); }, ), SizedBox(width: 15.w), ATDebounceWidget( child: Container( alignment: Alignment.center, width: 95.w, height: 35.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(25.w)), gradient: LinearGradient( colors: [Color(0xffF31216), Color(0xffFF8B8D)], begin: Alignment.topLeft, end: Alignment.bottomRight, ), boxShadow: [ BoxShadow( color: Color(0xffA289EC), offset: Offset(0, 4), blurRadius: 4, ), ], ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Image.asset( "atu_images/dynamic/at_icon_like.png", height: 20.w, ), SizedBox(width: 3.w), text( ATAppLocalizations.of(context)!.like, fontSize: 14.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), ), onTap: () { ATNavigatorUtils.push( context, DynamicRoute.dynamicMessageLike, replace: false, ); }, ), SizedBox(width: 15.w), ATDebounceWidget( child: Container( alignment: Alignment.center, width: 95.w, height: 35.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(25.w)), gradient: LinearGradient( colors: [Color(0xff9226FF), Color(0xffB070FF)], begin: Alignment.topLeft, end: Alignment.bottomRight, ), boxShadow: [ BoxShadow( color: Color(0xffA289EC), offset: Offset(0, 4), blurRadius: 4, ), ], ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Image.asset( "atu_images/dynamic/at_icon_dy_gift.png", height: 20.w, ), SizedBox(width: 3.w), text( ATAppLocalizations.of(context)!.gift, fontSize: 14.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), ), onTap: () { ATNavigatorUtils.push( context, DynamicRoute.dynamicMessageGift, replace: false, ); }, ), ], ), ), Expanded(child: 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), res.userId != AccountStorage().getCurrentUser()?.userProfile?.id ? ((res.subscription ?? false) ? Container() : ATDebounceWidget( child: Container( alignment: AlignmentDirectional.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(12.w), gradient: LinearGradient( colors: [Color(0xff7726FF), Color(0xffC670FF)], ), ), width: 68.w, height: 23.w, child: text( ATAppLocalizations.of(context)!.follow, textColor: Colors.white, fontWeight: FontWeight.w600, fontSize: 13.sp, ), ), onTap: () { AccountRepository() .followUser(res.userId ?? "") .then((result) { res.setSubscription(true); setState(() {}); }); }, )) : Container(), ATDebounceWidget( child: Container( child: Icon( Icons.more_vert, color: Colors.black45, size: 18.w, ), padding: EdgeInsetsDirectional.all(3.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( 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( fontSize: 14.sp, color: Colors.black, fontWeight: FontWeight.w600, ), // 按行截断 trimCollapsedText: ATAppLocalizations.of(context)!.showMore, // 收缩时按钮文字 trimExpandedText: ATAppLocalizations.of(context)!.showLess, // 展开时按钮文字 moreStyle: TextStyle( color: ChatVibeTheme.primaryLight, fontWeight: FontWeight.w600, ), lessStyle: TextStyle( color: ChatVibeTheme.primaryLight, 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 == 1 ? 1 : (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 ?? 0})" : 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) onSuccess, Function? onErr, }) async { try { var result = await DynamicRepositoryImp().dynamicListLatest( 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); ATTts.show(ATAppLocalizations.of(context)!.deleteSuccessful); }); }) .catchError((e) {}); } }