From 2f4753ea6480565d39f5b606bf9d3917e08797c7 Mon Sep 17 00:00:00 2001 From: orz12 Date: Wed, 7 Feb 2024 18:34:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=82=B9=E8=B5=9E=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=9C=80=E6=96=B0=E4=B8=8E=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg_feed_top/like_me/controller.dart | 9 +- lib/pages/msg_feed_top/like_me/view.dart | 218 +++++++++--------- 2 files changed, 121 insertions(+), 106 deletions(-) diff --git a/lib/pages/msg_feed_top/like_me/controller.dart b/lib/pages/msg_feed_top/like_me/controller.dart index c4440bc5a..4430c73fa 100644 --- a/lib/pages/msg_feed_top/like_me/controller.dart +++ b/lib/pages/msg_feed_top/like_me/controller.dart @@ -4,7 +4,8 @@ import 'package:pilipala/http/msg.dart'; import '../../../models/msg/msgfeed_like_me.dart'; class LikeMeController extends GetxController { - RxList msgFeedLikeMeList = [].obs; + RxList msgFeedLikeMeLatestList = [].obs; + RxList msgFeedLikeMeTotalList = [].obs; bool isLoading = false; int cursor = -1; int cursorTime = -1; @@ -19,9 +20,11 @@ class LikeMeController extends GetxController { MsgFeedLikeMe data = MsgFeedLikeMe.fromJson(res['data']); isEnd = data.total?.cursor?.isEnd ?? false; if (cursor == -1) { - msgFeedLikeMeList.assignAll(data.total!.items!); + msgFeedLikeMeLatestList.assignAll(data.latest?.items??[]); + msgFeedLikeMeTotalList.assignAll(data.total?.items??[]); } else { - msgFeedLikeMeList.addAll(data.total!.items!); + msgFeedLikeMeLatestList.addAll(data.latest?.items??[]); + msgFeedLikeMeTotalList.addAll(data.total?.items??[]); } cursor = data.total?.cursor?.id ?? -1; cursorTime = data.total?.cursor?.time ?? -1; diff --git a/lib/pages/msg_feed_top/like_me/view.dart b/lib/pages/msg_feed_top/like_me/view.dart index 2fc3ba2d1..41b57f958 100644 --- a/lib/pages/msg_feed_top/like_me/view.dart +++ b/lib/pages/msg_feed_top/like_me/view.dart @@ -4,6 +4,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; +import '../../../models/msg/msgfeed_like_me.dart'; import 'controller.dart'; class LikeMePage extends StatefulWidget { @@ -50,113 +51,42 @@ class _LikeMePageState extends State { builder: (BuildContext context, BoxConstraints constraints) { return Obx( () { - if (_likeMeController.msgFeedLikeMeList.isEmpty) { + if (_likeMeController.msgFeedLikeMeLatestList.isEmpty && + _likeMeController.msgFeedLikeMeTotalList.isEmpty) { return const Center( child: CircularProgressIndicator(), ); } - return ListView.separated( - itemCount: _likeMeController.msgFeedLikeMeList.length, - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (_, int i) { - return ListTile( - onTap: () { - String nativeUri = _likeMeController - .msgFeedLikeMeList[i].item?.nativeUri ?? - ""; - SmartDialog.showToast("跳转至:$nativeUri(暂未实现)"); - }, - leading: SizedBox( - width: 50, - height: 50, - child: Stack( - children: [ - for (var j = 0; - j < - _likeMeController.msgFeedLikeMeList[i] - .users!.length && - j < 4; - j++) ...[ - Positioned( - left: 15 * (j % 2).toDouble(), - top: 15 * (j ~/ 2).toDouble(), - child: NetworkImgLayer( - width: _likeMeController - .msgFeedLikeMeList[i] - .users! - .length > - 1 - ? 30 - : 45, - height: _likeMeController - .msgFeedLikeMeList[i] - .users! - .length > - 1 - ? 30 - : 45, - type: 'avatar', - src: _likeMeController - .msgFeedLikeMeList[i] - .users![j] - .avatar, - )), - ] - ], - )), - title: Text( - "${_likeMeController.msgFeedLikeMeList[i].users!.map((e) => e.nickname).join("、")} " - "赞了我的${_likeMeController.msgFeedLikeMeList[i].item?.business}", - style: Theme.of(context).textTheme.bodyMedium!, - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), - subtitle: - _likeMeController.msgFeedLikeMeList[i].item?.title != - null && - _likeMeController - .msgFeedLikeMeList[i].item?.title != - "" - ? Text( - _likeMeController - .msgFeedLikeMeList[i].item?.title ?? - "", - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: Theme.of(context) - .textTheme - .labelMedium! - .copyWith( - color: Theme.of(context) - .colorScheme - .outline)) - : null, - trailing: - _likeMeController.msgFeedLikeMeList[i].item?.image != - null && - _likeMeController - .msgFeedLikeMeList[i].item?.image != - "" - ? NetworkImgLayer( - width: 45, - height: 45, - type: 'cover', - src: _likeMeController - .msgFeedLikeMeList[i].item?.image, - ) - : null, - ); - }, - separatorBuilder: (BuildContext context, int index) { - return Divider( - indent: 72, - endIndent: 20, - height: 6, - color: Colors.grey.withOpacity(0.1), - ); - }, - ); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (_likeMeController + .msgFeedLikeMeLatestList.isNotEmpty) ...[ + Text(" 最新", + style: Theme.of(context) + .textTheme + .labelMedium! + .copyWith( + color: + Theme.of(context).colorScheme.outline)), + LikeMeList( + msgFeedLikeMeList: + _likeMeController.msgFeedLikeMeLatestList), + ], + if (_likeMeController + .msgFeedLikeMeTotalList.isNotEmpty) ...[ + Text(" 累计", + style: Theme.of(context) + .textTheme + .labelMedium! + .copyWith( + color: + Theme.of(context).colorScheme.outline)), + LikeMeList( + msgFeedLikeMeList: + _likeMeController.msgFeedLikeMeTotalList), + ] + ]); }, ); }), @@ -165,3 +95,85 @@ class _LikeMePageState extends State { ); } } + +class LikeMeList extends StatelessWidget { + const LikeMeList({ + super.key, + required this.msgFeedLikeMeList, + }); + final RxList msgFeedLikeMeList; + + @override + Widget build(BuildContext context) { + return ListView.separated( + itemCount: msgFeedLikeMeList.length, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (_, int i) { + return ListTile( + onTap: () { + String nativeUri = msgFeedLikeMeList[i].item?.nativeUri ?? ""; + SmartDialog.showToast("跳转至:$nativeUri(暂未实现)"); + }, + leading: SizedBox( + width: 50, + height: 50, + child: Stack( + children: [ + for (var j = 0; + j < msgFeedLikeMeList[i].users!.length && j < 4; + j++) ...[ + Positioned( + left: 15 * (j % 2).toDouble(), + top: 15 * (j ~/ 2).toDouble(), + child: NetworkImgLayer( + width: + msgFeedLikeMeList[i].users!.length > 1 ? 30 : 45, + height: + msgFeedLikeMeList[i].users!.length > 1 ? 30 : 45, + type: 'avatar', + src: msgFeedLikeMeList[i].users![j].avatar, + )), + ] + ], + )), + title: Text( + "${msgFeedLikeMeList[i].users!.map((e) => e.nickname).join("/")}" + "等共 ${msgFeedLikeMeList[i].counts} 人" + "赞了我的${msgFeedLikeMeList[i].item?.business}", + style: + Theme.of(context).textTheme.labelMedium!.copyWith(height: 1.5), + maxLines: 2, + overflow: TextOverflow.ellipsis, + ), + subtitle: msgFeedLikeMeList[i].item?.title != null && + msgFeedLikeMeList[i].item?.title != "" + ? Text(msgFeedLikeMeList[i].item?.title ?? "", + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: Theme.of(context).textTheme.labelMedium!.copyWith( + color: Theme.of(context).colorScheme.outline, + height: 1.5)) + : null, + trailing: msgFeedLikeMeList[i].item?.image != null && + msgFeedLikeMeList[i].item?.image != "" + ? NetworkImgLayer( + width: 45, + height: 45, + type: 'cover', + src: msgFeedLikeMeList[i].item?.image, + ) + : null, + ); + }, + separatorBuilder: (BuildContext context, int index) { + return Divider( + indent: 72, + endIndent: 20, + height: 6, + color: Colors.grey.withOpacity(0.1), + ); + }, + ); + } +}