From 88587c10da459ce0b1969fc52228e049b291857b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 16 Oct 2024 22:38:01 +0800 Subject: [PATCH] :sparkles: Notification embed post --- lib/screens/account/notification.dart | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/screens/account/notification.dart b/lib/screens/account/notification.dart index 4e5efc4..a29fd3f 100644 --- a/lib/screens/account/notification.dart +++ b/lib/screens/account/notification.dart @@ -2,9 +2,12 @@ import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:get/get.dart'; import 'package:solian/models/notification.dart'; +import 'package:solian/models/post.dart'; import 'package:solian/providers/notifications.dart'; +import 'package:solian/router.dart'; import 'package:solian/widgets/loading_indicator.dart'; import 'package:solian/widgets/markdown_text_content.dart'; +import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/relative_date.dart'; import 'package:uuid/uuid.dart'; @@ -150,6 +153,15 @@ class _NotificationScreenState extends State { parentId: 'notification-${element.id}', ), + if ([ + 'interactive.feedback', + 'interactive.subscription' + ].contains(element.topic) && + element.metadata?['related_post'] != + null) + _PostRelatedNotificationWidget( + metadata: element.metadata!, + ), const Gap(8), Opacity( opacity: 0.75, @@ -230,3 +242,31 @@ class NotificationButton extends StatelessWidget { }); } } + +class _PostRelatedNotificationWidget extends StatelessWidget { + final Map metadata; + + const _PostRelatedNotificationWidget({super.key, required this.metadata}); + + @override + Widget build(BuildContext context) { + return GestureDetector( + child: Card( + margin: const EdgeInsets.symmetric(vertical: 4), + child: PostItem( + item: Post.fromJson(metadata['related_post']), + isCompact: true, + ).paddingAll(8), + ), + onTap: () { + final data = Post.fromJson(metadata['related_post']); + Navigator.pop(context); + AppRouter.instance.pushNamed( + 'postDetail', + pathParameters: {'id': data.id.toString()}, + extra: data, + ); + }, + ); + } +}