From 32739821ba87627d80ec9b2304448eb259c5bd30 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 1 Dec 2024 20:08:04 +0800 Subject: [PATCH] :sparkles: Publisher popover --- assets/translations/en.json | 4 + assets/translations/zh.json | 4 + lib/widgets/post/post_item.dart | 26 ++++++- lib/widgets/post/publisher_popover.dart | 99 +++++++++++++++++++++++++ pubspec.lock | 8 ++ pubspec.yaml | 1 + 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 lib/widgets/post/publisher_popover.dart diff --git a/assets/translations/en.json b/assets/translations/en.json index 4e983bd..ef7501b 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -99,6 +99,10 @@ "publishersNew": "New Publisher", "publisherNewSubtitle": "Create a new publisher identity.", "publisherSyncWithAccount": "Sync with account", + "publisherTotalUpvote": "Upvote", + "publisherTotalDownvote": "Downvote", + "publisherSocialPoint": "Social Point", + "publisherJoinedAt": "Joined At", "fieldPublisherBelongToRealm": "Belongs to", "fieldPublisherBelongToRealmUnset": "Unset Publisher Belongs to Realm", "writePostTypeStory": "Post a story", diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 3a7459a..6baabb4 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -99,6 +99,10 @@ "publishersNew": "新发布者", "publisherNewSubtitle": "创建一个新的公共身份。", "publisherSyncWithAccount": "同步账户信息", + "publisherTotalUpvote": "总顶数", + "publisherTotalDownvote": "总踩数", + "publisherSocialPoint": "社会信用点", + "publisherJoinedAt": "加入于", "fieldPublisherBelongToRealm": "所属领域", "fieldPublisherBelongToRealmUnset": "未设置发布者所属领域", "writePostTypeStory": "发动态", diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index a575e67..625c822 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:material_symbols_icons/symbols.dart'; +import 'package:popover/popover.dart'; import 'package:provider/provider.dart'; import 'package:relative_time/relative_time.dart'; import 'package:styled_widget/styled_widget.dart'; @@ -15,6 +16,7 @@ import 'package:surface/widgets/markdown_content.dart'; import 'package:gap/gap.dart'; import 'package:surface/widgets/post/post_comment_list.dart'; import 'package:surface/widgets/post/post_reaction.dart'; +import 'package:surface/widgets/post/publisher_popover.dart'; class PostItem extends StatelessWidget { final SnPost data; @@ -264,9 +266,27 @@ class _PostContentHeader extends StatelessWidget { return Row( children: [ - AccountImage( - content: data.publisher.avatar, - radius: isCompact ? 12 : 20, + GestureDetector( + child: AccountImage( + content: data.publisher.avatar, + radius: isCompact ? 12 : 20, + ), + onTap: () { + showPopover( + context: context, + transition: PopoverTransition.other, + bodyBuilder: (context) => SizedBox( + width: 400, + child: PublisherPopoverCard( + data: data.publisher, + ).padding(horizontal: 16, vertical: 16), + ), + direction: PopoverDirection.bottom, + arrowHeight: 5, + arrowWidth: 15, + arrowDxOffset: -190, + ); + }, ), Gap(isCompact ? 8 : 12), if (isCompact) diff --git a/lib/widgets/post/publisher_popover.dart b/lib/widgets/post/publisher_popover.dart new file mode 100644 index 0000000..29dd7a1 --- /dev/null +++ b/lib/widgets/post/publisher_popover.dart @@ -0,0 +1,99 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; +import 'package:material_symbols_icons/symbols.dart'; +import 'package:styled_widget/styled_widget.dart'; +import 'package:surface/types/post.dart'; +import 'package:surface/widgets/account/account_image.dart'; + +class PublisherPopoverCard extends StatelessWidget { + final SnPublisher data; + const PublisherPopoverCard({super.key, required this.data}); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AccountImage( + content: data.avatar, + radius: 20, + ), + Gap(16), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text(data.nick).bold(), + Text('@${data.name}').fontSize(13).opacity(0.75), + ], + ), + ), + IconButton( + onPressed: () {}, + icon: const Icon(Symbols.chevron_right), + padding: EdgeInsets.zero, + visualDensity: const VisualDensity(horizontal: -4, vertical: -4), + ), + const Gap(8) + ], + ), + const Gap(16), + Row( + children: [ + Expanded( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text('publisherSocialPoint').tr().fontSize(13).opacity(0.75), + Text((data.totalUpvote - data.totalDownvote).toString()), + ], + ), + ), + SizedBox( + height: 20, + child: const VerticalDivider( + thickness: 1, + ), + ).padding(horizontal: 8), + Expanded( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text('publisherTotalUpvote').tr().fontSize(13).opacity(0.75), + Text(data.totalUpvote.toString()), + ], + ), + ), + SizedBox( + height: 20, + child: const VerticalDivider( + thickness: 1, + ), + ).padding(horizontal: 8), + Expanded( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text('publisherTotalDownvote') + .tr() + .fontSize(13) + .opacity(0.75), + Text(data.totalDownvote.toString()), + ], + ), + ), + ], + ), + ], + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index e539341..81a220d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1330,6 +1330,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.5.1" + popover: + dependency: "direct main" + description: + name: popover + sha256: "0606f3e10f92fc0459f5c52fd917738c29e7552323b28694d50c2d3312d0e1a2" + url: "https://pub.dev" + source: hosted + version: "0.3.1" protobuf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 85cad53..51dfa00 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -93,6 +93,7 @@ dependencies: wakelock_plus: ^1.2.8 permission_handler: ^11.3.1 flutter_staggered_grid_view: ^0.7.0 + popover: ^0.3.1 dev_dependencies: flutter_test: