Show post visibility

This commit is contained in:
LittleSheep 2024-10-13 20:45:00 +08:00
parent 1809f2557d
commit c21ca5573c
3 changed files with 30 additions and 2 deletions

View File

@ -24,6 +24,7 @@ class Post {
String? alias;
String? areaAlias;
dynamic body;
int visibility;
List<Tag>? tags;
List<Category>? categories;
List<Post>? 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,

View File

@ -20,6 +20,7 @@ Post _$PostFromJson(Map<String, dynamic> 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<dynamic>?)
?.map((e) => Tag.fromJson(e as Map<String, dynamic>))
.toList(),
@ -67,6 +68,7 @@ Map<String, dynamic> _$PostToJson(Post instance) => <String, dynamic>{
'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(),

View File

@ -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<PostItem> {
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),
),
],
),
],
),
),