diff --git a/lib/controller/home/timeline_info_controller.dart b/lib/controller/home/timeline_info_controller.dart index acaad91..b2b13fe 100644 --- a/lib/controller/home/timeline_info_controller.dart +++ b/lib/controller/home/timeline_info_controller.dart @@ -193,7 +193,7 @@ class TimelineInfoController extends GetxController { if (emoji != null) { widgets.add( Padding( - padding: EdgeInsets.symmetric(horizontal: 2.w), + padding: EdgeInsets.symmetric(horizontal: 0), child: Image.asset( emoji.path, width: 24.w, diff --git a/lib/pages/home/send_timeline.dart b/lib/pages/home/send_timeline.dart index b1544cf..53d1a33 100644 --- a/lib/pages/home/send_timeline.dart +++ b/lib/pages/home/send_timeline.dart @@ -374,7 +374,7 @@ class _SendTimelineState extends State { if (emoji != null) { widgets.add( Padding( - padding: EdgeInsets.symmetric(horizontal: 2.w), + padding: EdgeInsets.symmetric(horizontal: 0), child: Image.asset( emoji.path, width: 24.w, @@ -513,6 +513,7 @@ class _SendTimelineState extends State { child: IgnorePointer( child: SingleChildScrollView( child: Wrap( + crossAxisAlignment: WrapCrossAlignment.center, children: buildInputContentWidgets(), ), ), diff --git a/lib/pages/home/timeline_info.dart b/lib/pages/home/timeline_info.dart index ae83383..4f39b21 100644 --- a/lib/pages/home/timeline_info.dart +++ b/lib/pages/home/timeline_info.dart @@ -21,324 +21,349 @@ class TimelineInfo extends StatelessWidget { return GetX( init: TimelineInfoController(id: id), builder: (controller) { - return Scaffold( - appBar: PageAppbar(title: "详情"), - body: Stack( - children: [ - if(controller.item.value.id != null && controller.item.value.id != "") 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.commentList.clear(); - await controller.getPostData(); - await controller.getCommentData(); - controller.listRefreshController.finishRefresh(IndicatorResult.success); - controller.listRefreshController.finishLoad(IndicatorResult.none); - }, - // 上拉加载更多 - onLoad: () async { - print('推荐列表上拉加载被触发, hasMore: '); - controller.page.value += 1; - controller.getCommentData(); + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Get.back(result: controller.item.value); + }, + child: Scaffold( + appBar: AppBar( + leading: BackButton( + onPressed: () { + Get.back(result: controller.item.value); }, - child: SingleChildScrollView( - child: Container( - padding: EdgeInsets.symmetric( - horizontal: 16.w, - vertical: 10.w - ), + ), + backgroundColor: const Color.fromRGBO(255, 255, 255, 1), + surfaceTintColor: const Color.fromRGBO(255, 255, 255, 1), + centerTitle: true, + title: Text( + "详情", + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: const Color.fromRGBO(51, 51, 51, 1) + ), + ), + ), + body: Stack( + children: [ + if(controller.item.value.id != null && controller.item.value.id != "") 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.commentList.clear(); + await controller.getPostData(); + await controller.getCommentData(); + controller.listRefreshController.finishRefresh(IndicatorResult.success); + controller.listRefreshController.finishLoad(IndicatorResult.none); + }, + // 上拉加载更多 + onLoad: () async { + print('推荐列表上拉加载被触发, hasMore: '); + controller.page.value += 1; + controller.getCommentData(); + }, + child: SingleChildScrollView( + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 16.w, + vertical: 10.w + ), - constraints: BoxConstraints( - minHeight: MediaQuery.of(context).size.height - MediaQuery.of(context).padding.top, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - ClipRRect( - borderRadius: BorderRadius.all(Radius.circular(40.w)), - child: CachedNetworkImage( - imageUrl: controller.item.value.profilePhoto ?? "", - width: 40.w, - height: 40.w, - fit: BoxFit.cover, - ), - ).onTap((){ - Get.to(() => UserInformationPage(miId: controller.item.value.miId ?? "", userId: controller.item.value.userId ?? "",)); - }), - SizedBox(width: 8.w,), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - controller.item.value.nickName ?? "", - style: TextStyle( - fontSize: 13.w, - fontWeight: FontWeight.w500 - ), + constraints: BoxConstraints( + minHeight: MediaQuery.of(context).size.height - MediaQuery.of(context).padding.top, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + ClipRRect( + borderRadius: BorderRadius.all(Radius.circular(40.w)), + child: CachedNetworkImage( + imageUrl: controller.item.value.profilePhoto ?? "", + width: 40.w, + height: 40.w, + fit: BoxFit.cover, ), - Text( - controller.item.value.createTime ?? "", - style: TextStyle( - fontSize: 11.w, - color: const Color.fromRGBO(51, 51, 51, .6), - fontWeight: FontWeight.w500 + ).onTap((){ + Get.to(() => UserInformationPage(miId: controller.item.value.miId ?? "", userId: controller.item.value.userId ?? "",)); + }), + SizedBox(width: 8.w,), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + controller.item.value.nickName ?? "", + style: TextStyle( + fontSize: 13.w, + fontWeight: FontWeight.w500 + ), ), - ) - ], - ) - ], - ), - PopupMenuButton( - tooltip: "", - padding: EdgeInsets.zero, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), - color: Colors.white, - elevation: 8, - offset: Offset(0, 32.w), // 相对按钮下移一点 - itemBuilder: (context) => [ - const PopupMenuItem(value: 'report', child: Text('举报')), - ], - onSelected: (v) { - if (v == 'report') { - print("举报"); - Get.to(() => ReportPage(id: id,)); - } - }, - child: Icon( - Icons.keyboard_control, - size: 15.w, - color: const Color.fromRGBO(51, 51, 51, 1), - ), // 你的小圆按钮 - ), - ], - ), - Container( - margin: EdgeInsets.symmetric(vertical: 11.w), - child: !controller.item.value.content!.contains('[emoji:') ? Text( + Text( + controller.item.value.createTime ?? "", + style: TextStyle( + fontSize: 11.w, + color: const Color.fromRGBO(51, 51, 51, .6), + fontWeight: FontWeight.w500 + ), + ) + ], + ) + ], + ), + PopupMenuButton( + tooltip: "", + padding: EdgeInsets.zero, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), + color: Colors.white, + elevation: 8, + offset: Offset(0, 32.w), // 相对按钮下移一点 + itemBuilder: (context) => [ + const PopupMenuItem(value: 'report', child: Text('举报')), + ], + onSelected: (v) { + if (v == 'report') { + print("举报"); + Get.to(() => ReportPage(id: id,)); + } + }, + child: Icon( + Icons.keyboard_control, + size: 15.w, + color: const Color.fromRGBO(51, 51, 51, 1), + ), // 你的小圆按钮 + ), + ], + ), + Container( + margin: EdgeInsets.symmetric(vertical: 11.w), + child: !controller.item.value.content!.contains('[emoji:') ? Text( - controller.item.value.content ?? "", - ) : Wrap( - children: controller.buildInputContentWidgets(), + controller.item.value.content ?? "", + ) : Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + children: controller.buildInputContentWidgets(), + ), ), - ), - if(controller.imgList.length == 1) CachedNetworkImage( - imageUrl: controller.imgList[0], - width: 341.w, - height: 341.w, - fit: BoxFit.cover, - ), - if(controller.imgList.length == 2) Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ...controller.imgList.map((e){ - return CachedNetworkImage( - imageUrl: e, - width: 165.w, - height: 165.w, - fit: BoxFit.cover, - ); - }), - ], - ), - if(controller.imgList.length > 2) Wrap( - spacing: 13.w, - runSpacing: 13.w, - children: [ - ...controller.imgList.map((e){ - return CachedNetworkImage( - imageUrl: e, - width: 105.w, - height: 105.w, - fit: BoxFit.cover, - ); - }), - ], - ), - SizedBox(height: 15.w,), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Row( - children: [ - Image.asset( - (controller.item.value.isLiked ?? false) ? Assets.imagesLikeActive : Assets.imagesLikeIcon, - width: 14.w, - height: 12.w, - ), - SizedBox(width: 6.w,), - Text( - "${controller.item.value.likeCount ?? 0}", - style: TextStyle( - fontSize: 11.w, - color: const Color.fromRGBO(144, 144, 144, .6) + if(controller.imgList.length == 1) CachedNetworkImage( + imageUrl: controller.imgList[0], + width: 341.w, + height: 341.w, + fit: BoxFit.cover, + ), + if(controller.imgList.length == 2) Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ...controller.imgList.map((e){ + return CachedNetworkImage( + imageUrl: e, + width: 165.w, + height: 165.w, + fit: BoxFit.cover, + ); + }), + ], + ), + if(controller.imgList.length > 2) Wrap( + spacing: 13.w, + runSpacing: 13.w, + children: [ + ...controller.imgList.map((e){ + return CachedNetworkImage( + imageUrl: e, + width: 105.w, + height: 105.w, + fit: BoxFit.cover, + ); + }), + ], + ), + SizedBox(height: 15.w,), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + children: [ + Image.asset( + (controller.item.value.isLiked ?? false) ? Assets.imagesLikeActive : Assets.imagesLikeIcon, + width: 14.w, + height: 12.w, ), - ) - ], - ).onTap((){ - controller.likePost(); - }), - SizedBox(width: 33.w,), - Row( - children: [ - Image.asset( - Assets.imagesCommentIcon, - width: 15.w, - height: 15.w, - ), - SizedBox(width: 6.w,), - Text( - "${controller.item.value.commentCount ?? 0}", - style: TextStyle( - fontSize: 11.w, - color: const Color.fromRGBO(144, 144, 144, .6) + SizedBox(width: 6.w,), + Text( + "${controller.item.value.likeCount ?? 0}", + style: TextStyle( + fontSize: 11.w, + color: const Color.fromRGBO(144, 144, 144, .6) + ), + ) + ], + ).onTap((){ + controller.likePost(); + }), + SizedBox(width: 33.w,), + Row( + children: [ + Image.asset( + Assets.imagesCommentIcon, + width: 15.w, + height: 15.w, ), - ) - ], - ).onTap((){ - controller.showInput.value = true; + SizedBox(width: 6.w,), + Text( + "${controller.item.value.commentCount ?? 0}", + style: TextStyle( + fontSize: 11.w, + color: const Color.fromRGBO(144, 144, 144, .6) + ), + ) + ], + ).onTap((){ + controller.showInput.value = true; - }), - ], - ), - SizedBox(height: 18.w,), - Text( - "全部评论(${controller.item.value.commentCount ?? 0})", - style: TextStyle( - fontSize: 13.w, - color: const Color.fromRGBO(144, 144, 144, 1), - fontWeight: FontWeight.w500 + }), + ], ), - ), - SizedBox(height: 20.w,), + SizedBox(height: 18.w,), + Text( + "全部评论(${controller.item.value.commentCount ?? 0})", + style: TextStyle( + fontSize: 13.w, + color: const Color.fromRGBO(144, 144, 144, 1), + fontWeight: FontWeight.w500 + ), + ), + SizedBox(height: 20.w,), - ...controller.commentList.map((e){ - return CommentItem(item: e, controller: controller,); - }), - ], + ...controller.commentList.map((e){ + return CommentItem(item: e, controller: controller,); + }), + ], + ), ), ), ), - ), - if(controller.showInput.value) Positioned.fill( - child: Container( - color: const Color.fromRGBO(0, 0, 0, .4), - ).onTap((){ - controller.showInput.value = false; + if(controller.showInput.value) Positioned.fill( + child: Container( + color: const Color.fromRGBO(0, 0, 0, .4), + ).onTap((){ + controller.showInput.value = false; - }), - ), - if(controller.showInput.value) Positioned( - left: 0, - bottom: 0, - child: Container( - width: 375.w, - height: 60.w, - color: Colors.white, - padding: EdgeInsets.all(10.w), - child: Row( - children: [ - Expanded( - child: Container( - decoration: BoxDecoration( - color: const Color.fromRGBO(247, 247, 247, 1), - borderRadius: BorderRadius.all(Radius.circular(40.w)) - ), - child: TextField( - controller: controller.messageController.value, - autofocus: true, - style: TextStyle( - fontSize: ScreenUtil().setWidth(14), - height: 1 + }), + ), + if(controller.showInput.value) Positioned( + left: 0, + bottom: 0, + child: Container( + width: 375.w, + height: 60.w, + color: Colors.white, + padding: EdgeInsets.all(10.w), + child: Row( + children: [ + Expanded( + child: Container( + decoration: BoxDecoration( + color: const Color.fromRGBO(247, 247, 247, 1), + borderRadius: BorderRadius.all(Radius.circular(40.w)) ), - decoration: InputDecoration( - contentPadding: EdgeInsets.symmetric( - vertical: 0, - horizontal: 17.w + child: TextField( + controller: controller.messageController.value, + autofocus: true, + style: TextStyle( + fontSize: ScreenUtil().setWidth(14), + height: 1 ), - hintText: "请输入评论", + decoration: InputDecoration( + contentPadding: EdgeInsets.symmetric( + vertical: 0, + horizontal: 17.w + ), + hintText: "请输入评论", - border: const OutlineInputBorder( - borderSide: BorderSide.none, // 这将移除边框 // 可选:设置圆角 - ), - // 如果你希望聚焦时和未聚焦时都没有边框,也可以设置 focusedBorder 和 enabledBorder - focusedBorder: const OutlineInputBorder( - borderSide: BorderSide.none, - borderRadius: BorderRadius.all(Radius.circular(4.0)), - ), - enabledBorder: const OutlineInputBorder( - borderSide: BorderSide.none, - borderRadius: BorderRadius.all(Radius.circular(4.0)), + border: const OutlineInputBorder( + borderSide: BorderSide.none, // 这将移除边框 // 可选:设置圆角 + ), + // 如果你希望聚焦时和未聚焦时都没有边框,也可以设置 focusedBorder 和 enabledBorder + focusedBorder: const OutlineInputBorder( + borderSide: BorderSide.none, + borderRadius: BorderRadius.all(Radius.circular(4.0)), + ), + enabledBorder: const OutlineInputBorder( + borderSide: BorderSide.none, + borderRadius: BorderRadius.all(Radius.circular(4.0)), + ), ), + onChanged: (value){ + controller.message.value = value; + }, ), - onChanged: (value){ - controller.message.value = value; - }, ), ), - ), - Container( - width: 60.w, - height: 30.w, + Container( + width: 60.w, + height: 30.w, - margin: EdgeInsets.only(left: 15.w), - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(30.w)), - gradient: LinearGradient( - begin: Alignment.centerLeft, // 0%:左边开始 - end: Alignment.centerRight, // 100%:右边结束 - colors: [ - Color.fromRGBO(131, 89, 255, 1), // 紫色 - Color.fromRGBO(77, 127, 231, 1), // 中间淡蓝 - Color.fromRGBO(61, 138, 224, 1), // 右侧深蓝 - ], - stops: [0.0, 0.7753, 1.0], // 对应 CSS 百分比:0%、77.53%、100% + margin: EdgeInsets.only(left: 15.w), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(30.w)), + gradient: LinearGradient( + begin: Alignment.centerLeft, // 0%:左边开始 + end: Alignment.centerRight, // 100%:右边结束 + colors: [ + Color.fromRGBO(131, 89, 255, 1), // 紫色 + Color.fromRGBO(77, 127, 231, 1), // 中间淡蓝 + Color.fromRGBO(61, 138, 224, 1), // 右侧深蓝 + ], + stops: [0.0, 0.7753, 1.0], // 对应 CSS 百分比:0%、77.53%、100% + ), ), - ), - child: Center( - child: Text( - "发送", - style: TextStyle( - fontSize: 12.w, - color: Colors.white + child: Center( + child: Text( + "发送", + style: TextStyle( + fontSize: 12.w, + color: Colors.white + ), ), ), - ), - ).onTap((){ - controller.sendComment(); - }) - ], + ).onTap((){ + controller.sendComment(); + }) + ], + ), ), - ), - ) - ], + ) + ], + ), ), ); }, diff --git a/lib/pages/home/timeline_item.dart b/lib/pages/home/timeline_item.dart index ecefb79..ea042af 100644 --- a/lib/pages/home/timeline_item.dart +++ b/lib/pages/home/timeline_item.dart @@ -3,11 +3,13 @@ import 'package:dating_touchme_app/config/emoji_config.dart'; import 'package:dating_touchme_app/extension/ex_widget.dart'; import 'package:dating_touchme_app/generated/assets.dart'; import 'package:dating_touchme_app/model/home/post_data.dart'; +import 'package:dating_touchme_app/network/home_api.dart'; import 'package:dating_touchme_app/pages/home/report_page.dart'; import 'package:dating_touchme_app/pages/home/timeline_info.dart'; import 'package:dating_touchme_app/pages/home/user_information_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; class TimelineItem extends StatefulWidget { @@ -49,7 +51,7 @@ class _TimelineItemState extends State { if (emoji != null) { widgets.add( Padding( - padding: EdgeInsets.symmetric(horizontal: 2.w), + padding: EdgeInsets.symmetric(horizontal: 0), child: Image.asset( emoji.path, width: 24.w, @@ -80,9 +82,14 @@ class _TimelineItemState extends State { List imgList = []; + late final HomeApi _homeApi; + @override void initState() { super.initState(); + + + _homeApi = Get.find(); getImgList(); } @@ -96,6 +103,39 @@ class _TimelineItemState extends State { } } + + + likePost() async { + try { + final response = await _homeApi.userLikePost({ + "id": widget.item.id, + "isLiked": !(widget.item.isLiked ?? false), + }); + if (response.data.isSuccess) { + if(widget.item.isLiked ?? false){ + SmartDialog.showToast('取消点赞成功'); + widget.item.likeCount = widget.item.likeCount! - 1; + } else { + SmartDialog.showToast('点赞成功'); + widget.item.likeCount = widget.item.likeCount! + 1; + } + widget.item.isLiked = !(widget.item.isLiked ?? false); + setState(() { + + }); + } else { + + // 响应失败,抛出异常 + throw Exception(response.data.message ?? '获取数据失败'); + } + } catch(e){ + print('帖子发布失败: $e'); + SmartDialog.showToast('帖子发布失败'); + rethrow; + + } + } + @override Widget build(BuildContext context) { return Container( @@ -173,6 +213,7 @@ class _TimelineItemState extends State { child: !widget.item.content!.contains('[emoji:') ? Text( widget.item.content ?? "" ) : Wrap( + crossAxisAlignment: WrapCrossAlignment.center, children: buildInputContentWidgets(), ), ), @@ -230,7 +271,9 @@ class _TimelineItemState extends State { ), ) ], - ), + ).onTap((){ + likePost(); + }), SizedBox(width: 33.w,), Row( children: [ @@ -254,7 +297,14 @@ class _TimelineItemState extends State { ], ), ).onTap((){ - Get.to(() => TimelineInfo(id: widget.item.id ?? "",)); + Get.to(() => TimelineInfo(id: widget.item.id ?? "",))?.then((e){ + widget.item.likeCount = e.likeCount; + widget.item.isLiked = e.isLiked; + widget.item.commentCount = e.commentCount; + setState(() { + + }); + }); }); } }