From 063c087089468777c795787956460ca5a102ff3e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 14 Oct 2024 22:58:37 +0800 Subject: [PATCH] :sparkles: Post show more button --- lib/screens/posts/post_detail.dart | 22 +++++++++++++++++++++- lib/widgets/posts/post_item.dart | 17 +++++++++++++---- lib/widgets/posts/post_list.dart | 1 + 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/screens/posts/post_detail.dart b/lib/screens/posts/post_detail.dart index 4fc7037..bbae3ee 100644 --- a/lib/screens/posts/post_detail.dart +++ b/lib/screens/posts/post_detail.dart @@ -6,6 +6,7 @@ import 'package:solian/providers/content/posts.dart'; import 'package:solian/providers/last_read.dart'; import 'package:solian/theme.dart'; import 'package:solian/widgets/loading_indicator.dart'; +import 'package:solian/widgets/posts/post_action.dart'; import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_replies.dart'; @@ -40,7 +41,7 @@ class _PostDetailScreenState extends State { Get.find().feedLastReadAt = _item?.id; - setState(() => _isBusy = false); + if (mounted) setState(() => _isBusy = false); } @override @@ -67,6 +68,7 @@ class _PostDetailScreenState extends State { ), SliverToBoxAdapter( child: PostItem( + key: ValueKey(_item), item: _item!, isClickable: false, isOverrideEmbedClickable: true, @@ -79,6 +81,24 @@ class _PostDetailScreenState extends State { vertical: 8, ) : EdgeInsets.zero, + onTapMore: () { + showModalBottomSheet( + useRootNavigator: true, + context: context, + builder: (context) => PostAction( + item: _item!, + noReact: true, + ), + ).then((value) { + if (value is Future) { + value.then((_) { + _getDetail(); + }); + } else if (value != null) { + _getDetail(); + } + }); + }, ), ), SliverToBoxAdapter( diff --git a/lib/widgets/posts/post_item.dart b/lib/widgets/posts/post_item.dart index 1545ef8..698664b 100644 --- a/lib/widgets/posts/post_item.dart +++ b/lib/widgets/posts/post_item.dart @@ -38,6 +38,7 @@ class PostItem extends StatefulWidget { final EdgeInsets? padding; final Function? onComment; + final Function? onTapMore; const PostItem({ super.key, @@ -55,6 +56,7 @@ class PostItem extends StatefulWidget { this.attachmentParent, this.padding, this.onComment, + this.onTapMore, }); @override @@ -99,6 +101,7 @@ class _PostItemState extends State { _PostHeaderWidget( isCompact: widget.isCompact, isFullDate: widget.isFullDate, + onTapMore: widget.onTapMore, item: item, ).paddingSymmetric(horizontal: 12), _PostHeaderDividerWidget(item: item).paddingSymmetric(horizontal: 12), @@ -161,6 +164,7 @@ class _PostItemState extends State { _PostHeaderWidget( isCompact: widget.isCompact, isFullDate: widget.isFullDate, + onTapMore: widget.onTapMore, item: item, ), _PostHeaderDividerWidget(item: item), @@ -588,10 +592,13 @@ class _PostHeaderWidget extends StatelessWidget { final bool isFullDate; final Post item; + final Function? onTapMore; + const _PostHeaderWidget({ required this.isCompact, required this.isFullDate, required this.item, + required this.onTapMore, }); @override @@ -649,10 +656,12 @@ class _PostHeaderWidget extends StatelessWidget { ], ), ), - if (item.type == 'article') - Badge( - label: Text('article'.tr), - ).paddingOnly(top: 3), + if (onTapMore != null) + IconButton( + color: Theme.of(context).colorScheme.primary, + icon: const Icon(Icons.more_vert), + onPressed: () => onTapMore!(), + ), ], ), const Gap(8), diff --git a/lib/widgets/posts/post_list.dart b/lib/widgets/posts/post_list.dart index f5349af..75562ae 100644 --- a/lib/widgets/posts/post_list.dart +++ b/lib/widgets/posts/post_list.dart @@ -105,6 +105,7 @@ class PostListEntryWidget extends StatelessWidget { isClickable: isNestedClickable, showFeaturedReply: showFeaturedReply, padding: padding, + onTapMore: () => _openActions(context), onComment: () { AppRouter.instance .pushNamed(