From c21ca5573c0e3b826c98e59ea9012eb184a8faa4 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 13 Oct 2024 20:45:00 +0800 Subject: [PATCH] :sparkles: Show post visibility --- lib/models/post.dart | 2 ++ lib/models/post.g.dart | 2 ++ lib/widgets/posts/post_item.dart | 28 ++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/models/post.dart b/lib/models/post.dart index 54190df..92feebc 100755 --- a/lib/models/post.dart +++ b/lib/models/post.dart @@ -24,6 +24,7 @@ class Post { String? alias; String? areaAlias; dynamic body; + int visibility; List? tags; List? categories; List? replies; @@ -55,6 +56,7 @@ class Post { required this.areaAlias, required this.type, required this.body, + required this.visibility, required this.tags, required this.categories, required this.replies, diff --git a/lib/models/post.g.dart b/lib/models/post.g.dart index 7ec5d4e..05b2e49 100644 --- a/lib/models/post.g.dart +++ b/lib/models/post.g.dart @@ -20,6 +20,7 @@ Post _$PostFromJson(Map json) => Post( areaAlias: json['area_alias'] as String?, type: json['type'] as String, body: json['body'], + visibility: (json['visibility'] as num).toInt(), tags: (json['tags'] as List?) ?.map((e) => Tag.fromJson(e as Map)) .toList(), @@ -67,6 +68,7 @@ Map _$PostToJson(Post instance) => { 'alias': instance.alias, 'area_alias': instance.areaAlias, 'body': instance.body, + 'visibility': instance.visibility, 'tags': instance.tags?.map((e) => e.toJson()).toList(), 'categories': instance.categories?.map((e) => e.toJson()).toList(), 'replies': instance.replies?.map((e) => e.toJson()).toList(), diff --git a/lib/widgets/posts/post_item.dart b/lib/widgets/posts/post_item.dart index 4b4c7cf..ace08a4 100644 --- a/lib/widgets/posts/post_item.dart +++ b/lib/widgets/posts/post_item.dart @@ -1,6 +1,5 @@ import 'package:animations/animations.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:gap/gap.dart'; @@ -66,6 +65,14 @@ class _PostItemState extends State { Color get _unFocusColor => Theme.of(context).colorScheme.onSurface.withOpacity(0.75); + static final visibilityIcons = [ + Icons.public, + Icons.group, + Icons.visibility, + Icons.visibility_off, + Icons.lock, + ]; + @override void initState() { item = widget.item; @@ -612,7 +619,24 @@ class _PostHeaderWidget extends StatelessWidget { ], ), if (!isCompact) - RelativeDate(item.publishedAt?.toLocal() ?? DateTime.now()), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + RelativeDate( + item.publishedAt?.toLocal() ?? DateTime.now(), + isFull: isFullDate, + ), + const Gap(4), + Icon( + _PostItemState.visibilityIcons[item.visibility], + size: 16, + color: Theme.of(context) + .colorScheme + .onSurface + .withOpacity(0.75), + ), + ], + ), ], ), ),