From 2ec9cd814d343b261672c6b3f07bf1d8ed91172a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 20 May 2024 23:39:23 +0800 Subject: [PATCH] :sparkles: Attachment badges --- lib/providers/content/attachment_item.dart | 48 ++++++++++++++++++-- lib/translations.dart | 2 + lib/widgets/attachments/attachment_list.dart | 10 +++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/lib/providers/content/attachment_item.dart b/lib/providers/content/attachment_item.dart index 6a85311..86bd83e 100644 --- a/lib/providers/content/attachment_item.dart +++ b/lib/providers/content/attachment_item.dart @@ -1,20 +1,58 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:solian/models/attachment.dart'; import 'package:solian/services.dart'; class AttachmentItem extends StatelessWidget { final Attachment item; + final String? badge; + final bool show; + final Function onHide; - const AttachmentItem({super.key, required this.item}); + const AttachmentItem({ + super.key, + required this.item, + required this.onHide, + this.badge, + this.show = true, + }); @override Widget build(BuildContext context) { return Hero( tag: Key('a${item.uuid}'), - child: Image.network( - '${ServiceFinder.services['paperclip']}/api/attachments/${item.id}', - fit: BoxFit.cover, + child: Stack( + fit: StackFit.expand, + children: [ + Image.network( + '${ServiceFinder.services['paperclip']}/api/attachments/${item.id}', + fit: BoxFit.cover, + ), + if (show && badge != null) + Positioned( + right: 12, + bottom: 8, + child: Material( + color: Colors.transparent, + child: Chip(label: Text(badge!)), + ), + ), + if (show && item.isMature) + Positioned( + top: 8, + left: 12, + child: Material( + color: Colors.transparent, + child: ActionChip( + visualDensity: const VisualDensity(vertical: -4, horizontal: -4), + avatar: Icon(Icons.visibility_off, color: Theme.of(context).colorScheme.onSurfaceVariant), + label: Text('hide'.tr), + onPressed: () => onHide(), + ), + ), + ), + ], ), ); } -} \ No newline at end of file +} diff --git a/lib/translations.dart b/lib/translations.dart index 831b98c..737a2a8 100644 --- a/lib/translations.dart +++ b/lib/translations.dart @@ -4,6 +4,7 @@ class SolianMessages extends Translations { @override Map> get keys => { 'en_US': { + 'hide': 'Hide', 'okay': 'Okay', 'next': 'Next', 'page': 'Page', @@ -52,6 +53,7 @@ class SolianMessages extends Translations { 'attachmentAlt': 'Alternative text', }, 'zh_CN': { + 'hide': '隐藏', 'okay': '确认', 'next': '下一步', 'cancel': '取消', diff --git a/lib/widgets/attachments/attachment_list.dart b/lib/widgets/attachments/attachment_list.dart index 81a2f67..b89d129 100644 --- a/lib/widgets/attachments/attachment_list.dart +++ b/lib/widgets/attachments/attachment_list.dart @@ -121,7 +121,15 @@ class _AttachmentListState extends State { child: Stack( fit: StackFit.expand, children: [ - AttachmentItem(key: Key('a${element!.uuid}'), item: element), + AttachmentItem( + key: Key('a${element!.uuid}'), + item: element, + badge: _attachmentsMeta.length > 1 ? '${idx+1}/${_attachmentsMeta.length}' : null, + show: !element.isMature || _showMature, + onHide: () { + setState(() => _showMature = false); + }, + ), if (element.isMature && !_showMature) BackdropFilter( filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),