From 013e82e61db5278d92666ba535eab7cafe1da284 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Thu, 23 May 2024 11:54:43 +0200 Subject: [PATCH] fix: add post deletion in the timeline userstory --- CHANGELOG.md | 1 + .../flutter_timeline_gorouter_userstory.dart | 8 +++- .../flutter_timeline_navigator_userstory.dart | 7 ++- .../lib/src/screens/timeline_post_screen.dart | 45 ++----------------- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a58fd7..9f8b315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - fix the avatar size to match the new design - Add the iconbutton for image uploading back to the ReactionBottom - Fix category key is correctly used for saving timeline posts and category title is shown everywhere +- Fix when clicking on post delete in the post screen of the userstory it will now navigate back to the timeline and delete the post ## 3.0.1 diff --git a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart index 5a34d81..3f4935f 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart @@ -154,7 +154,13 @@ List getTimelineStoryRoutes({ options: config.optionsBuilder(context), service: service, post: post!, - onPostDelete: () => config.onPostDelete?.call(context, post), + onPostDelete: () async => + config.onPostDelete?.call(context, post) ?? + () async { + await service.postService.deletePost(post); + if (!context.mounted) return; + context.go(TimelineUserStoryRoutes.timelineHome); + }.call(), onUserTap: (user) => config.onUserTap?.call(context, user), ); diff --git a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart index e25b67c..250fbf7 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart @@ -132,7 +132,12 @@ Widget _postDetailScreenRoute({ post: post, onPostDelete: () async => config.onPostDelete?.call(context, post) ?? - await config.service.postService.deletePost(post), + () async { + await config.service.postService.deletePost(post); + if (context.mounted) { + Navigator.of(context).pop(); + } + }.call(), onUserTap: (user) => config.onUserTap?.call(context, user), ); diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart index 41d8a27..1bc6922 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart @@ -15,7 +15,7 @@ import 'package:flutter_timeline_view/src/widgets/reaction_bottom.dart'; import 'package:flutter_timeline_view/src/widgets/tappable_image.dart'; import 'package:intl/intl.dart'; -class TimelinePostScreen extends StatelessWidget { +class TimelinePostScreen extends StatefulWidget { const TimelinePostScreen({ required this.userId, required this.service, @@ -47,47 +47,10 @@ class TimelinePostScreen extends StatelessWidget { final bool? isOverviewScreen; @override - Widget build(BuildContext context) => _TimelinePostScreen( - userId: userId, - service: service, - options: options, - post: post, - onPostDelete: onPostDelete, - onUserTap: onUserTap, - isOverviewScreen: isOverviewScreen, - ); + State createState() => _TimelinePostScreenState(); } -class _TimelinePostScreen extends StatefulWidget { - const _TimelinePostScreen({ - required this.userId, - required this.service, - required this.options, - required this.post, - required this.onPostDelete, - this.onUserTap, - this.isOverviewScreen, - }); - - final String userId; - - final TimelineService service; - - final TimelineOptions options; - - final TimelinePost post; - - final Function(String userId)? onUserTap; - - final VoidCallback onPostDelete; - - final bool? isOverviewScreen; - - @override - State<_TimelinePostScreen> createState() => _TimelinePostScreenState(); -} - -class _TimelinePostScreenState extends State<_TimelinePostScreen> { +class _TimelinePostScreenState extends State { TimelinePost? post; bool isLoading = true; @@ -231,7 +194,7 @@ class _TimelinePostScreenState extends State<_TimelinePostScreen> { if (widget.options.allowAllDeletion || post.creator?.userId == widget.userId) PopupMenuButton( - onSelected: (value) => widget.onPostDelete(), + onSelected: (value) => widget.onPostDelete.call(), itemBuilder: (BuildContext context) => >[ PopupMenuItem(