Skip to content

Commit

Permalink
feat: 点赞支持显示最新与人数
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 7, 2024
1 parent e2bd514 commit 2f4753e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 106 deletions.
9 changes: 6 additions & 3 deletions lib/pages/msg_feed_top/like_me/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import 'package:pilipala/http/msg.dart';
import '../../../models/msg/msgfeed_like_me.dart';

class LikeMeController extends GetxController {
RxList<LikeMeItems> msgFeedLikeMeList = <LikeMeItems>[].obs;
RxList<LikeMeItems> msgFeedLikeMeLatestList = <LikeMeItems>[].obs;
RxList<LikeMeItems> msgFeedLikeMeTotalList = <LikeMeItems>[].obs;
bool isLoading = false;
int cursor = -1;
int cursorTime = -1;
Expand All @@ -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;
Expand Down
218 changes: 115 additions & 103 deletions lib/pages/msg_feed_top/like_me/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -50,113 +51,42 @@ class _LikeMePageState extends State<LikeMePage> {
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++) ...<Widget>[
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) ...<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),
]
]);
},
);
}),
Expand All @@ -165,3 +95,85 @@ class _LikeMePageState extends State<LikeMePage> {
);
}
}

class LikeMeList extends StatelessWidget {
const LikeMeList({
super.key,
required this.msgFeedLikeMeList,
});
final RxList<LikeMeItems> 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++) ...<Widget>[
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),
);
},
);
}
}

0 comments on commit 2f4753e

Please sign in to comment.