🐛 Fix notification screen error

This commit is contained in:
LittleSheep 2024-11-26 21:56:01 +08:00
parent 6a3cd0a60d
commit bedffbfad7
5 changed files with 100 additions and 82 deletions

View File

@ -197,11 +197,24 @@ class _NotificationScreenState extends State<NotificationScreen> {
'interactive.subscription' 'interactive.subscription'
].contains(nty.topic) && ].contains(nty.topic) &&
nty.metadata['related_post'] != null) nty.metadata['related_post'] != null)
PostItem( StyledWidget(Container(
data: SnPost.fromJson( decoration: BoxDecoration(
nty.metadata['related_post']!, borderRadius: const BorderRadius.all(
Radius.circular(8)),
border: Border.all(
color: Theme.of(context).dividerColor,
width: 1,
),
), ),
), child: PostItem(
data: SnPost.fromJson(
nty.metadata['related_post']!,
),
showComments: false,
showReactions: false,
showMenu: false,
),
)).padding(top: 8),
const Gap(8), const Gap(8),
Row( Row(
children: [ children: [

View File

@ -18,8 +18,8 @@ class SnPost with _$SnPost {
required String language, required String language,
required String? alias, required String? alias,
required String? aliasPrefix, required String? aliasPrefix,
required List<dynamic> tags, @Default([]) List<dynamic> tags,
required List<dynamic> categories, @Default([]) List<dynamic> categories,
required List<SnPost>? replies, required List<SnPost>? replies,
required int? replyId, required int? replyId,
required int? repostId, required int? repostId,

View File

@ -583,8 +583,8 @@ class _$SnPostImpl extends _SnPost {
required this.language, required this.language,
required this.alias, required this.alias,
required this.aliasPrefix, required this.aliasPrefix,
required final List<dynamic> tags, final List<dynamic> tags = const [],
required final List<dynamic> categories, final List<dynamic> categories = const [],
required final List<SnPost>? replies, required final List<SnPost>? replies,
required this.replyId, required this.replyId,
required this.repostId, required this.repostId,
@ -642,6 +642,7 @@ class _$SnPostImpl extends _SnPost {
final String? aliasPrefix; final String? aliasPrefix;
final List<dynamic> _tags; final List<dynamic> _tags;
@override @override
@JsonKey()
List<dynamic> get tags { List<dynamic> get tags {
if (_tags is EqualUnmodifiableListView) return _tags; if (_tags is EqualUnmodifiableListView) return _tags;
// ignore: implicit_dynamic_type // ignore: implicit_dynamic_type
@ -650,6 +651,7 @@ class _$SnPostImpl extends _SnPost {
final List<dynamic> _categories; final List<dynamic> _categories;
@override @override
@JsonKey()
List<dynamic> get categories { List<dynamic> get categories {
if (_categories is EqualUnmodifiableListView) return _categories; if (_categories is EqualUnmodifiableListView) return _categories;
// ignore: implicit_dynamic_type // ignore: implicit_dynamic_type
@ -850,8 +852,8 @@ abstract class _SnPost extends SnPost {
required final String language, required final String language,
required final String? alias, required final String? alias,
required final String? aliasPrefix, required final String? aliasPrefix,
required final List<dynamic> tags, final List<dynamic> tags,
required final List<dynamic> categories, final List<dynamic> categories,
required final List<SnPost>? replies, required final List<SnPost>? replies,
required final int? replyId, required final int? replyId,
required final int? repostId, required final int? repostId,

View File

@ -18,8 +18,8 @@ _$SnPostImpl _$$SnPostImplFromJson(Map<String, dynamic> json) => _$SnPostImpl(
language: json['language'] as String, language: json['language'] as String,
alias: json['alias'] as String?, alias: json['alias'] as String?,
aliasPrefix: json['alias_prefix'] as String?, aliasPrefix: json['alias_prefix'] as String?,
tags: json['tags'] as List<dynamic>, tags: json['tags'] as List<dynamic>? ?? const [],
categories: json['categories'] as List<dynamic>, categories: json['categories'] as List<dynamic>? ?? const [],
replies: (json['replies'] as List<dynamic>?) replies: (json['replies'] as List<dynamic>?)
?.map((e) => SnPost.fromJson(e as Map<String, dynamic>)) ?.map((e) => SnPost.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),

View File

@ -18,6 +18,7 @@ class PostItem extends StatelessWidget {
final SnPost data; final SnPost data;
final bool showReactions; final bool showReactions;
final bool showComments; final bool showComments;
final bool showMenu;
final double? maxWidth; final double? maxWidth;
final Function(SnPost data)? onChanged; final Function(SnPost data)? onChanged;
const PostItem({ const PostItem({
@ -25,6 +26,7 @@ class PostItem extends StatelessWidget {
required this.data, required this.data,
this.showReactions = true, this.showReactions = true,
this.showComments = true, this.showComments = true,
this.showMenu = true,
this.maxWidth, this.maxWidth,
this.onChanged, this.onChanged,
}); });
@ -43,7 +45,7 @@ class PostItem extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
_PostContentHeader(data: data) _PostContentHeader(data: data, showMenu: showMenu)
.padding(horizontal: 12, vertical: 8), .padding(horizontal: 12, vertical: 8),
if (data.body['title'] != null || if (data.body['title'] != null ||
data.body['description'] != null) data.body['description'] != null)
@ -62,7 +64,7 @@ class PostItem extends StatelessWidget {
], ],
), ),
), ),
if (data.preload?.attachments?.isNotEmpty ?? true) if (data.preload?.attachments?.isNotEmpty ?? false)
AttachmentList( AttachmentList(
data: data.preload!.attachments!, data: data.preload!.attachments!,
bordered: true, bordered: true,
@ -107,70 +109,71 @@ class _PostBottomAction extends StatelessWidget {
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Row( if (showReactions || showComments)
children: [ Row(
if (showReactions) children: [
InkWell( if (showReactions)
child: Row( InkWell(
children: [ child: Row(
Icon(Symbols.add_reaction, size: 20, color: iconColor), children: [
const Gap(8), Icon(Symbols.add_reaction, size: 20, color: iconColor),
if (data.totalUpvote > 0 && const Gap(8),
data.totalUpvote >= data.totalDownvote) if (data.totalUpvote > 0 &&
Text('postReactionUpvote').plural( data.totalUpvote >= data.totalDownvote)
data.totalUpvote, Text('postReactionUpvote').plural(
) data.totalUpvote,
else if (data.totalDownvote > 0) )
Text('postReactionDownvote').plural( else if (data.totalDownvote > 0)
data.totalDownvote, Text('postReactionDownvote').plural(
) data.totalDownvote,
else )
Text('postReact').tr(), else
], Text('postReact').tr(),
).padding(horizontal: 8, vertical: 8), ],
onTap: () { ).padding(horizontal: 8, vertical: 8),
showModalBottomSheet( onTap: () {
context: context, showModalBottomSheet(
builder: (context) => PostReactionPopup( context: context,
data: data, builder: (context) => PostReactionPopup(
onChanged: (value, attr, delta) { data: data,
onChanged(data.copyWith( onChanged: (value, attr, delta) {
totalUpvote: attr == 1 onChanged(data.copyWith(
? data.totalUpvote + delta totalUpvote: attr == 1
: data.totalUpvote, ? data.totalUpvote + delta
totalDownvote: attr == 2 : data.totalUpvote,
? data.totalDownvote + delta totalDownvote: attr == 2
: data.totalDownvote, ? data.totalDownvote + delta
metric: data.metric.copyWith(reactionList: value), : data.totalDownvote,
)); metric: data.metric.copyWith(reactionList: value),
}, ));
), },
); ),
}, );
), },
if (showComments) ),
InkWell( if (showComments)
child: Row( InkWell(
children: [ child: Row(
Icon(Symbols.comment, size: 20, color: iconColor), children: [
const Gap(8), Icon(Symbols.comment, size: 20, color: iconColor),
Text('postComments').plural(data.metric.replyCount), const Gap(8),
], Text('postComments').plural(data.metric.replyCount),
).padding(horizontal: 8, vertical: 8), ],
onTap: () { ).padding(horizontal: 8, vertical: 8),
showModalBottomSheet( onTap: () {
context: context, showModalBottomSheet(
useRootNavigator: true, context: context,
builder: (context) => PostCommentListPopup( useRootNavigator: true,
postId: data.id, builder: (context) => PostCommentListPopup(
commentCount: data.metric.replyCount, postId: data.id,
), commentCount: data.metric.replyCount,
); ),
}, );
), },
].expand((ele) => [ele, const Gap(8)]).toList() ),
..removeLast(), ].expand((ele) => [ele, const Gap(8)]).toList()
), ..removeLast(),
),
InkWell( InkWell(
child: Icon( child: Icon(
Symbols.share, Symbols.share,
@ -211,11 +214,11 @@ class _PostHeadline extends StatelessWidget {
class _PostContentHeader extends StatelessWidget { class _PostContentHeader extends StatelessWidget {
final SnPost data; final SnPost data;
final bool isCompact; final bool isCompact;
final bool showActions; final bool showMenu;
const _PostContentHeader({ const _PostContentHeader({
required this.data, required this.data,
this.isCompact = false, this.isCompact = false,
this.showActions = true, this.showMenu = true,
}); });
@override @override
@ -264,7 +267,7 @@ class _PostContentHeader extends StatelessWidget {
], ],
), ),
), ),
if (showActions) if (showMenu)
PopupMenuButton( PopupMenuButton(
icon: const Icon(Symbols.more_horiz), icon: const Icon(Symbols.more_horiz),
style: const ButtonStyle( style: const ButtonStyle(
@ -376,7 +379,7 @@ class _PostQuoteContent extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Column( child: Column(
children: [ children: [
_PostContentHeader(data: child, isCompact: true, showActions: false) _PostContentHeader(data: child, isCompact: true, showMenu: false)
.padding(bottom: 4), .padding(bottom: 4),
_PostContentBody(data: child.body), _PostContentBody(data: child.body),
], ],