feat: 点赞支持显示最新与人数

This commit is contained in:
orz12
2024-02-07 18:34:15 +08:00
parent e2bd5146e1
commit 2f4753ea64
2 changed files with 121 additions and 106 deletions

View File

@@ -4,7 +4,8 @@ import 'package:pilipala/http/msg.dart';
import '../../../models/msg/msgfeed_like_me.dart'; import '../../../models/msg/msgfeed_like_me.dart';
class LikeMeController extends GetxController { class LikeMeController extends GetxController {
RxList<LikeMeItems> msgFeedLikeMeList = <LikeMeItems>[].obs; RxList<LikeMeItems> msgFeedLikeMeLatestList = <LikeMeItems>[].obs;
RxList<LikeMeItems> msgFeedLikeMeTotalList = <LikeMeItems>[].obs;
bool isLoading = false; bool isLoading = false;
int cursor = -1; int cursor = -1;
int cursorTime = -1; int cursorTime = -1;
@@ -19,9 +20,11 @@ class LikeMeController extends GetxController {
MsgFeedLikeMe data = MsgFeedLikeMe.fromJson(res['data']); MsgFeedLikeMe data = MsgFeedLikeMe.fromJson(res['data']);
isEnd = data.total?.cursor?.isEnd ?? false; isEnd = data.total?.cursor?.isEnd ?? false;
if (cursor == -1) { if (cursor == -1) {
msgFeedLikeMeList.assignAll(data.total!.items!); msgFeedLikeMeLatestList.assignAll(data.latest?.items??[]);
msgFeedLikeMeTotalList.assignAll(data.total?.items??[]);
} else { } else {
msgFeedLikeMeList.addAll(data.total!.items!); msgFeedLikeMeLatestList.addAll(data.latest?.items??[]);
msgFeedLikeMeTotalList.addAll(data.total?.items??[]);
} }
cursor = data.total?.cursor?.id ?? -1; cursor = data.total?.cursor?.id ?? -1;
cursorTime = data.total?.cursor?.time ?? -1; cursorTime = data.total?.cursor?.time ?? -1;

View File

@@ -4,6 +4,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart';
import '../../../models/msg/msgfeed_like_me.dart';
import 'controller.dart'; import 'controller.dart';
class LikeMePage extends StatefulWidget { class LikeMePage extends StatefulWidget {
@@ -50,21 +51,68 @@ class _LikeMePageState extends State<LikeMePage> {
builder: (BuildContext context, BoxConstraints constraints) { builder: (BuildContext context, BoxConstraints constraints) {
return Obx( return Obx(
() { () {
if (_likeMeController.msgFeedLikeMeList.isEmpty) { if (_likeMeController.msgFeedLikeMeLatestList.isEmpty &&
_likeMeController.msgFeedLikeMeTotalList.isEmpty) {
return const Center( return const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
); );
} }
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_likeMeController
.msgFeedLikeMeLatestList.isNotEmpty) ...<Widget>[
Text(" 最新",
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline)),
LikeMeList(
msgFeedLikeMeList:
_likeMeController.msgFeedLikeMeLatestList),
],
if (_likeMeController
.msgFeedLikeMeTotalList.isNotEmpty) ...<Widget>[
Text(" 累计",
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline)),
LikeMeList(
msgFeedLikeMeList:
_likeMeController.msgFeedLikeMeTotalList),
]
]);
},
);
}),
),
),
);
}
}
class LikeMeList extends StatelessWidget {
const LikeMeList({
super.key,
required this.msgFeedLikeMeList,
});
final RxList<LikeMeItems> msgFeedLikeMeList;
@override
Widget build(BuildContext context) {
return ListView.separated( return ListView.separated(
itemCount: _likeMeController.msgFeedLikeMeList.length, itemCount: msgFeedLikeMeList.length,
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
itemBuilder: (_, int i) { itemBuilder: (_, int i) {
return ListTile( return ListTile(
onTap: () { onTap: () {
String nativeUri = _likeMeController String nativeUri = msgFeedLikeMeList[i].item?.nativeUri ?? "";
.msgFeedLikeMeList[i].item?.nativeUri ??
"";
SmartDialog.showToast("跳转至:$nativeUri(暂未实现)"); SmartDialog.showToast("跳转至:$nativeUri(暂未实现)");
}, },
leading: SizedBox( leading: SizedBox(
@@ -73,77 +121,47 @@ class _LikeMePageState extends State<LikeMePage> {
child: Stack( child: Stack(
children: [ children: [
for (var j = 0; for (var j = 0;
j < j < msgFeedLikeMeList[i].users!.length && j < 4;
_likeMeController.msgFeedLikeMeList[i]
.users!.length &&
j < 4;
j++) ...<Widget>[ j++) ...<Widget>[
Positioned( Positioned(
left: 15 * (j % 2).toDouble(), left: 15 * (j % 2).toDouble(),
top: 15 * (j ~/ 2).toDouble(), top: 15 * (j ~/ 2).toDouble(),
child: NetworkImgLayer( child: NetworkImgLayer(
width: _likeMeController width:
.msgFeedLikeMeList[i] msgFeedLikeMeList[i].users!.length > 1 ? 30 : 45,
.users! height:
.length > msgFeedLikeMeList[i].users!.length > 1 ? 30 : 45,
1
? 30
: 45,
height: _likeMeController
.msgFeedLikeMeList[i]
.users!
.length >
1
? 30
: 45,
type: 'avatar', type: 'avatar',
src: _likeMeController src: msgFeedLikeMeList[i].users![j].avatar,
.msgFeedLikeMeList[i]
.users![j]
.avatar,
)), )),
] ]
], ],
)), )),
title: Text( title: Text(
"${_likeMeController.msgFeedLikeMeList[i].users!.map((e) => e.nickname).join("")} " "${msgFeedLikeMeList[i].users!.map((e) => e.nickname).join("/")}"
"赞了我的${_likeMeController.msgFeedLikeMeList[i].item?.business}", "等共 ${msgFeedLikeMeList[i].counts}"
style: Theme.of(context).textTheme.bodyMedium!, "赞了我的${msgFeedLikeMeList[i].item?.business}",
style:
Theme.of(context).textTheme.labelMedium!.copyWith(height: 1.5),
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
subtitle: subtitle: msgFeedLikeMeList[i].item?.title != null &&
_likeMeController.msgFeedLikeMeList[i].item?.title != msgFeedLikeMeList[i].item?.title != ""
null && ? Text(msgFeedLikeMeList[i].item?.title ?? "",
_likeMeController
.msgFeedLikeMeList[i].item?.title !=
""
? Text(
_likeMeController
.msgFeedLikeMeList[i].item?.title ??
"",
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: Theme.of(context) style: Theme.of(context).textTheme.labelMedium!.copyWith(
.textTheme color: Theme.of(context).colorScheme.outline,
.labelMedium! height: 1.5))
.copyWith(
color: Theme.of(context)
.colorScheme
.outline))
: null, : null,
trailing: trailing: msgFeedLikeMeList[i].item?.image != null &&
_likeMeController.msgFeedLikeMeList[i].item?.image != msgFeedLikeMeList[i].item?.image != ""
null &&
_likeMeController
.msgFeedLikeMeList[i].item?.image !=
""
? NetworkImgLayer( ? NetworkImgLayer(
width: 45, width: 45,
height: 45, height: 45,
type: 'cover', type: 'cover',
src: _likeMeController src: msgFeedLikeMeList[i].item?.image,
.msgFeedLikeMeList[i].item?.image,
) )
: null, : null,
); );
@@ -157,11 +175,5 @@ class _LikeMePageState extends State<LikeMePage> {
); );
}, },
); );
},
);
}),
),
),
);
} }
} }